Class: Apfel::Line
- Inherits:
-
Object
- Object
- Apfel::Line
- Defined in:
- lib/apfel/line.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#in_comment ⇒ Object
Returns the value of attribute in_comment.
Instance Method Summary collapse
- #cleaned_content ⇒ Object
- #close_comment ⇒ Object
- #close_comment? ⇒ Boolean
- #empty_line? ⇒ Boolean
-
#initialize(line) ⇒ Line
constructor
A new instance of Line.
- #is_comment? ⇒ Boolean
- #key ⇒ Object
- #key_value_pair? ⇒ Boolean
- #open_comment ⇒ Object
- #open_comment? ⇒ Boolean
- #valid? ⇒ Boolean
- #value ⇒ Object
- #whole_comment ⇒ Object
- #whole_comment? ⇒ Boolean
Constructor Details
#initialize(line) ⇒ Line
Returns a new instance of Line.
6 7 8 9 10 |
# File 'lib/apfel/line.rb', line 6 def initialize(line) @content = line @in_comment = false raise "Line does not end in ;" unless valid? end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
3 4 5 |
# File 'lib/apfel/line.rb', line 3 def content @content end |
#in_comment ⇒ Object
Returns the value of attribute in_comment.
4 5 6 |
# File 'lib/apfel/line.rb', line 4 def in_comment @in_comment end |
Instance Method Details
#cleaned_content ⇒ Object
44 45 46 |
# File 'lib/apfel/line.rb', line 44 def cleaned_content content.gsub(/;\s*$/, "") end |
#close_comment ⇒ Object
32 33 34 |
# File 'lib/apfel/line.rb', line 32 def close_comment /^(.+)\*\/\s*$/.match(content).to_s end |
#close_comment? ⇒ Boolean
36 37 38 |
# File 'lib/apfel/line.rb', line 36 def close_comment? !(close_comment.empty?) end |
#empty_line? ⇒ Boolean
12 13 14 |
# File 'lib/apfel/line.rb', line 12 def empty_line? /^\s*$/.match(content) || false end |
#is_comment? ⇒ Boolean
68 69 70 |
# File 'lib/apfel/line.rb', line 68 def is_comment? whole_comment? || open_comment? || close_comment? || in_comment end |
#key ⇒ Object
56 57 58 59 60 |
# File 'lib/apfel/line.rb', line 56 def key if key_value_pair? cleaned_content.partition(/"\s*=\s*"/)[0].gsub!(/(^"|"$)/, "") end end |
#key_value_pair? ⇒ Boolean
40 41 42 |
# File 'lib/apfel/line.rb', line 40 def key_value_pair? !!(/^\s*"([^"]+)"\s*=/.match(content)) end |
#open_comment ⇒ Object
24 25 26 |
# File 'lib/apfel/line.rb', line 24 def open_comment /^\/\*(.+)$/.match(content).to_s end |
#open_comment? ⇒ Boolean
28 29 30 |
# File 'lib/apfel/line.rb', line 28 def open_comment? !(open_comment.empty?) end |
#valid? ⇒ Boolean
48 49 50 51 52 53 54 |
# File 'lib/apfel/line.rb', line 48 def valid? if key_value_pair? !!(/;[\s]*$/.match(content)) else true end end |
#value ⇒ Object
62 63 64 65 66 |
# File 'lib/apfel/line.rb', line 62 def value if key_value_pair? cleaned_content.partition(/"\s*=\s*"/)[2].gsub!(/(^"|"$)/, "") end end |
#whole_comment ⇒ Object
16 17 18 |
# File 'lib/apfel/line.rb', line 16 def whole_comment /((^\/\*(.+)\*\/)|(^\/\/(.+)))/.match(content).to_s end |
#whole_comment? ⇒ Boolean
20 21 22 |
# File 'lib/apfel/line.rb', line 20 def whole_comment? !(whole_comment.empty?) end |