Class: TwitterCldr::Resources::CldrDTD::Attr

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/resources/cldr_dtd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, element_name, dtd) ⇒ Attr

Returns a new instance of Attr.



13
14
15
16
17
# File 'lib/twitter_cldr/resources/cldr_dtd.rb', line 13

def initialize(name, element_name, dtd)
  @name = name
  @element_name = element_name
  @dtd = dtd
end

Instance Attribute Details

#dtdObject (readonly)

Returns the value of attribute dtd.



11
12
13
# File 'lib/twitter_cldr/resources/cldr_dtd.rb', line 11

def dtd
  @dtd
end

#element_nameObject (readonly)

Returns the value of attribute element_name.



11
12
13
# File 'lib/twitter_cldr/resources/cldr_dtd.rb', line 11

def element_name
  @element_name
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/twitter_cldr/resources/cldr_dtd.rb', line 11

def name
  @name
end

Instance Method Details

#valuesObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/twitter_cldr/resources/cldr_dtd.rb', line 19

def values
  @values ||= begin
    attr_line_idx = schema.find_index do |line|
      line.include?("<!ATTLIST #{element_name} #{name} ")
    end

    return [] unless attr_line_idx

    attr_line = schema[attr_line_idx]

    if comment = find_match_comment_after(attr_line_idx + 1)
      parse_match(comment)
    else
      start_idx = attr_line.index('(')
      return [] unless start_idx

      finish_idx = attr_line.rindex(')')
      attr_line[(start_idx + 1)...finish_idx].split('|').map(&:strip)
    end
  end
end