Class: Fit::ParseHolder

Inherits:
Object
  • Object
show all
Defined in:
lib/fit/parse.rb

Overview

This ParseHolder class is necessary to cope with the different constructors in the Java version of FIT. One of them is the constructor for the Parse Ruby class, the other is a static method in the ParseHolder class.

ParseHolder also maintain all the methods belonging to Parse which are instead called whenever in FIT a ParseHolder is created instead of a Parse.

Direct Known Subclasses

Parse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



24
25
26
# File 'lib/fit/parse.rb', line 24

def body
  @body
end

#endObject

Returns the value of attribute end.



24
25
26
# File 'lib/fit/parse.rb', line 24

def end
  @end
end

#leaderObject

Returns the value of attribute leader.



24
25
26
# File 'lib/fit/parse.rb', line 24

def leader
  @leader
end

#moreObject

Returns the value of attribute more.



25
26
27
# File 'lib/fit/parse.rb', line 25

def more
  @more
end

#partsObject

Returns the value of attribute parts.



25
26
27
# File 'lib/fit/parse.rb', line 25

def parts
  @parts
end

#tagObject

Returns the value of attribute tag.



24
25
26
# File 'lib/fit/parse.rb', line 24

def tag
  @tag
end

#trailerObject

Returns the value of attribute trailer.



24
25
26
# File 'lib/fit/parse.rb', line 24

def trailer
  @trailer
end

Class Method Details

.create(tag, body, parts, more) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fit/parse.rb', line 27

def ParseHolder.create tag, body, parts, more
  p = new
  p.leader = "\n"
  p.tag = "<#{tag}>"
  p.body = body
  p.end = "</#{tag}>"
  p.trailer = ""
  p.parts = parts
  p.more = more
  p
end

Instance Method Details

#add_to_body(text) ⇒ Object



47
48
49
# File 'lib/fit/parse.rb', line 47

def add_to_body text
  @body += text
end

#add_to_tag(text) ⇒ Object



43
44
45
# File 'lib/fit/parse.rb', line 43

def add_to_tag text
  @tag = @tag[0..-2] + "#{text}>"
end

#at(i, *rest) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/fit/parse.rb', line 51

def at i, *rest
  node = (i == 0 || @more.nil?) ? self : @more.at(i - 1)
  rest.each do |j|
    node = node.parts.at(j)
  end
  node
end

#lastObject



63
64
65
# File 'lib/fit/parse.rb', line 63

def last
  @more.nil? ? self : @more.last
end

#leafObject



39
40
41
# File 'lib/fit/parse.rb', line 39

def leaf
  @parts.nil? ? self : @parts.leaf
end


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/fit/parse.rb', line 71

def print out, conv=nil
  out.print conv.nil? ? @leader : conv.iconv(@leader)
  out.print conv.nil? ? @tag : conv.iconv(@tag)
  if @parts
    @parts.print out, conv
  else
    out.print conv.nil? ? @body : conv.iconv(@body)
  end
  out.print conv.nil? ? @end : conv.iconv(@end)
  if @more
    @more.print out, conv
  else
    out.print conv.nil? ? @trailer : conv.iconv(@end)
  end
end

#sizeObject



67
68
69
# File 'lib/fit/parse.rb', line 67

def size
  @more.nil? ? 1 : @more.size + 1
end

#textObject



59
60
61
# File 'lib/fit/parse.rb', line 59

def text
  Parse.html_to_text @body
end