Class: TwitterCldr::Formatters::Rbnf::RuleSet

Inherits:
Struct
  • Object
show all
Defined in:
lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#accessObject

Returns the value of attribute access

Returns:

  • (Object)

    the current value of access



12
13
14
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 12

def access
  @access
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



12
13
14
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 12

def name
  @name
end

#rulesObject

Returns the value of attribute rules

Returns:

  • (Object)

    the current value of rules



12
13
14
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 12

def rules
  @rules
end

Instance Method Details

#each_numeric_ruleObject



49
50
51
52
53
54
55
56
57
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 49

def each_numeric_rule
  if block_given?
    search_start_index.upto(rules.size - 1) do |i|
      yield rules[i]
    end
  else
    to_enum(:each_numeric_rule)
  end
end

#improper_fraction_ruleObject



29
30
31
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 29

def improper_fraction_rule
  rule_for_value(Rule::IMPROPER_FRACTION)
end

#master_ruleObject



25
26
27
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 25

def master_rule
  rule_for_value(Rule::MASTER)
end

#negative_ruleObject



37
38
39
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 37

def negative_rule
  rule_for_value(Rule::NEGATIVE)
end

#previous_rule_for(rule) ⇒ Object



19
20
21
22
23
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 19

def previous_rule_for(rule)
  if idx = rule_index_for(rule.base_value)
    rules[idx - 1] if idx > 0
  end
end

#private?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 41

def private?
  access == "private"
end

#proper_fraction_ruleObject



33
34
35
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 33

def proper_fraction_rule
  rule_for_value(Rule::PROPER_FRACTION)
end

#public?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 45

def public?
  access == "public"
end

#rule_for(number, fractional = false) ⇒ Object

fractional: i.e. whether or not to consider the rule set a “fractional” rule set (special rules apply)



60
61
62
63
64
65
66
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 60

def rule_for(number, fractional = false)
  if fractional
    fractional_rule_for(number)
  else
    normal_rule_for(number)
  end
end

#rule_for_value(base_value) ⇒ Object



13
14
15
16
17
# File 'lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb', line 13

def rule_for_value(base_value)
  if idx = rule_index_for(base_value)
    rules[idx]
  end
end