Class: TwitterCldr::Shared::NumberingSystem
- Inherits:
-
Object
- Object
- TwitterCldr::Shared::NumberingSystem
- Defined in:
- lib/twitter_cldr/shared/numbering_system.rb
Instance Attribute Summary collapse
-
#digits ⇒ Object
readonly
Returns the value of attribute digits.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, digits) ⇒ NumberingSystem
constructor
A new instance of NumberingSystem.
- #transliterate(number) ⇒ Object
Constructor Details
#initialize(name, digits) ⇒ NumberingSystem
Returns a new instance of NumberingSystem.
39 40 41 42 |
# File 'lib/twitter_cldr/shared/numbering_system.rb', line 39 def initialize(name, digits) @name = name @digits = split_digits(digits) end |
Instance Attribute Details
#digits ⇒ Object (readonly)
Returns the value of attribute digits.
37 38 39 |
# File 'lib/twitter_cldr/shared/numbering_system.rb', line 37 def digits @digits end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
37 38 39 |
# File 'lib/twitter_cldr/shared/numbering_system.rb', line 37 def name @name end |
Class Method Details
.for_name(name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/twitter_cldr/shared/numbering_system.rb', line 14 def for_name(name) system_cache[name] ||= begin if system = resource[name.to_sym] if system[:type] != "numeric" raise UnsupportedNumberingSystemError.new("#{system[:type]} numbering systems not supported.") else new(system[:name], system[:digits]) end end end end |
Instance Method Details
#transliterate(number) ⇒ Object
44 45 46 47 48 |
# File 'lib/twitter_cldr/shared/numbering_system.rb', line 44 def transliterate(number) number.to_s.gsub(/\d/) do |digit| digits[digit.to_i] end end |