Class: Burlap::BaseTag

Inherits:
Object show all
Defined in:
lib/burlap/base_tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ BaseTag

Returns a new instance of BaseTag.



6
7
8
9
10
11
# File 'lib/burlap/base_tag.rb', line 6

def initialize params={}
  params.each do |k,v|
    meffod = :"#{k}="
    send(meffod, v) if respond_to?(meffod)
  end
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



4
5
6
# File 'lib/burlap/base_tag.rb', line 4

def children
  @children
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/burlap/base_tag.rb', line 4

def name
  @name
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/burlap/base_tag.rb', line 4

def value
  @value
end

Instance Method Details

#parse_matched_pairsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/burlap/base_tag.rb', line 21

def parse_matched_pairs
  # The children are matched pairs.
  # We use an array here because ruby 1.8.x is _FUN_ to
  # use ordered hashes with and doing it in an array is
  # easier for now. Viva la 1.9!
  values = []

  self.children.each_slice(2) do |arr|
    key = arr.first.to_ruby
    value = if arr.last.name == "ref"
      i = arr.last.value.to_i - 1
      v = values[i]
      v.last if v
    else
      arr.last.to_ruby
    end

    values << [key, value]
  end

  values
end

#to_rubyObject



44
45
46
# File 'lib/burlap/base_tag.rb', line 44

def to_ruby
  Burlap.resolver.convert_to_native self
end