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

#fix_rule(rule) ⇒ Object



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

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

#pathObject



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

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")
        radix_attr.value
      else
        nil
      end
      
      attrs = {
        :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