Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get to 0 Duplication on Code Climate #326

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
DRY up inflection code.
Gaelan committed Oct 28, 2015
commit f30969d9ddbb4e3700720fe160c2106eb1c59fc3
20 changes: 12 additions & 8 deletions lib/volt/extra_core/inflector/inflections.rb
Original file line number Diff line number Diff line change
@@ -101,20 +101,16 @@ def acronym(word)
# either be a string or a regular expression. The replacement should
# always be a string that may include references to the matched data from
# the rule.
def plural(rule, replacement)
@uncountables.delete(rule) if rule.is_a?(String)
@uncountables.delete(replacement)
@plurals.insert(0, [rule, replacement])
def plural(*args)
register_pluralization_rule('plurals', *args)
end

# Specifies a new singularization rule and its replacement. The rule can
# either be a string or a regular expression. The replacement should
# always be a string that may include references to the matched data from
# the rule.
def singular(rule, replacement)
@uncountables.delete(rule) if rule.is_a?(String)
@uncountables.delete(replacement)
@singulars.insert(0, [rule, replacement])
def singular(*args)
register_pluralization_rule('singulars', *args)
end

# Specifies a new irregular that applies to both pluralization and
@@ -192,6 +188,14 @@ def clear(scope = :all)
instance_variable_set "@#{scope}", []
end
end

private

def register_pluralization_rule(type, rule, replacement)
@uncountables.delete(rule) if rule.is_a?(String)
@uncountables.delete(replacement)
instance_variable_get("@#{type}").insert(0, [rule, replacement])
end
end

# Yields a singleton instance of Inflector::Inflections so you can specify