Class: Cldr::Export::Data::Rbnf

Inherits:
Base
  • Object
show all
Defined in:
lib/cldr/export/data/rbnf.rb

Direct Known Subclasses

RbnfRoot

Instance Attribute Summary

Attributes inherited from Base

#locale

Instance Method Summary collapse

Methods inherited from Base

#[]=, #update

Methods inherited from Hash

#deep_merge, #deep_stringify_keys, #symbolize_keys

Constructor Details

#initialize(*args) ⇒ Rbnf

Returns a new instance of Rbnf.



8
9
10
11
# File 'lib/cldr/export/data/rbnf.rb', line 8

def initialize(*args)
  super
  update(:rbnf => { :grouping => rule_groups })
end

Instance Method Details

#cast_value(val) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/cldr/export/data/rbnf.rb', line 53

def cast_value(val)
  if val =~ /\A[\d]+\z/
    val.to_i
  else
    val
  end
end

#fix_rule(rule) ⇒ Object



61
62
63
# File 'lib/cldr/export/data/rbnf.rb', line 61

def fix_rule(rule)
  rule.gsub(/\A'/, '').gsub("", '<').gsub("", '>')
end

#pathObject



65
66
67
# File 'lib/cldr/export/data/rbnf.rb', line 65

def path
  @path ||= "#{Cldr::Export::Data.dir}/rbnf/#{locale.to_s.gsub('-', '_')}.xml"
end

#rule_groupsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cldr/export/data/rbnf.rb', line 13

def rule_groups
  if File.exist?(path)
    select("rbnf/rulesetGrouping").map do |grouping_node|
      {
        :type => grouping_node.attribute("type").value,
        :ruleset => (grouping_node / "ruleset").map do |ruleset_node|
          rule_set(ruleset_node)
        end
      }
    end
  else
    {}
  end
end

#rule_set(ruleset_node) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cldr/export/data/rbnf.rb', line 28

def rule_set(ruleset_node)
  attrs = {
    :type => ruleset_node.attribute("type").value,
    :rules => (ruleset_node / "rbnfrule").map do |rule_node|
      radix = if radix_attr = rule_node.attribute("radix")
        cast_value(radix_attr.value)
      else
        nil
      end

      attrs = {
        :value => cast_value(rule_node.attribute("value").value),
        :rule => fix_rule(rule_node.text)
      }

      attrs[:radix] = radix if radix
      attrs
    end
  }

  access = ruleset_node.attribute("access")
  attrs[:access] = access.value if access
  attrs
end