Class: Teepee::StringToken
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from ParserNode
#use_scope
Constructor Details
Returns a new instance of StringToken.
50
51
52
53
54
|
# File 'lib/teepee/string-token.rb', line 50
def initialize(text)
raise ArgumentError if not text.is_a? String
raise ArgumentError if not text =~ self.class.full_match_regex
@text = text
end
|
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
48
49
50
|
# File 'lib/teepee/string-token.rb', line 48
def text
@text
end
|
Class Method Details
.count_regex ⇒ Object
85
86
87
|
# File 'lib/teepee/string-token.rb', line 85
def count_regex
self::COUNT_REGEX
end
|
.front_match_regex ⇒ Object
81
82
83
|
# File 'lib/teepee/string-token.rb', line 81
def front_match_regex
self::FRONT_MATCH_REGEX
end
|
.full_match_regex ⇒ Object
77
78
79
|
# File 'lib/teepee/string-token.rb', line 77
def full_match_regex
self::FULL_MATCH_REGEX
end
|
.matches?(text) ⇒ Boolean
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/teepee/string-token.rb', line 89
def matches? text
if text =~ front_match_regex
count = text.index count_regex
if count.nil?
return [self.new(text), ""]
else
return [self.new(text[0 ... count]), text[count .. -1]]
end
else
return nil
end
end
|
Instance Method Details
#number? ⇒ Boolean
64
65
66
|
# File 'lib/teepee/string-token.rb', line 64
def number?
not to_number.nil?
end
|
#to_html ⇒ Object
60
61
62
|
# File 'lib/teepee/string-token.rb', line 60
def to_html
@text
end
|
#to_number ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/teepee/string-token.rb', line 68
def to_number
begin
Float(to_html)
rescue ArgumentError
nil
end
end
|
#to_s ⇒ Object
56
57
58
|
# File 'lib/teepee/string-token.rb', line 56
def to_s
@text
end
|