Module: CLDR::Parser

Included in:
Generator::LocaleData
Defined in:
lib/cldr/parser.rb

Instance Method Summary collapse

Instance Method Details

#attribute(key, type) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/cldr/parser.rb', line 16

def attribute(key, type)
  if @doc.elements[key]
    @doc.elements[key].attributes[type]
  else
    nil
  end
end

#attribute_only(var, meth, v, opts) ⇒ Object

parser functions.



25
26
27
28
29
30
31
32
33
# File 'lib/cldr/parser.rb', line 25

def attribute_only(var, meth, v, opts)
  attr = v.attributes[opts]
  if attr
    attr = ":empty:" if attr.size == 0
    {var.to_s => attr} 
  else
    {}
  end
end

#attribute_plural(var, meth, v, opts) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cldr/parser.rb', line 35

def attribute_plural(var, meth, v, opts)
  attr_type = v.attributes["type"]
  result = opts.collect{|opt| v.attributes[opt]}.compact
  if result.size > 0
    result << "|#{v.text}" if v.text
  else
    result = v.text if v.text
  end
  key = var.to_s
  key += "|#{attr_type}" if attr_type
  {key => result} 
end

#parse(var, meth, element, *opts) ⇒ Object

proposed > draft > normal.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cldr/parser.rb', line 49

def parse(var, meth, element, *opts)
  data = {}
  data_draft = {}
  data_proposed = {}
  key = opts.shift
  id = var.to_s
  id += "|" + element.attributes["type"] if element.attributes["type"]

  element.get_elements(key).each do |v|
    if opts.size > 1
      data.update(parse(id, meth, v, *opts))
    elsif opts.size == 1
      ret = send(meth, id, meth, v, *opts)
      if v.attributes["alt"] and v.attributes["alt"] == "proposed"
        data_proposed.update(ret)
      elsif v.attributes["draft"]
        data_draft.update(ret)
      else
        data.update(ret)
      end	    
    else
      child_id = id.dup
      child_id += "|" + v.attributes["type"] if v.attributes["type"]
      if v.attributes["alt"] and v.attributes["alt"] == "proposed"
        data_proposed[child_id] = v.text
      elsif v.attributes["draft"]
        data_draft[child_id] = v.text
      else
        data[child_id] = v.text
      end
    end
  end

  data.update(data_draft).update(data_proposed)
  data
end