Class: Apfel::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/apfel/line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject (readonly)

Returns the value of attribute content.



3
4
5
# File 'lib/apfel/line.rb', line 3

def content
  @content
end

#in_commentObject

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_contentObject



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

def cleaned_content
  content.gsub(/;\s*$/, "")
end

#close_commentObject



32
33
34
# File 'lib/apfel/line.rb', line 32

def close_comment
  /^(.+)\*\/\s*$/.match(content).to_s
end

#close_comment?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/apfel/line.rb', line 36

def close_comment?
  !(close_comment.empty?)
end

#empty_line?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/apfel/line.rb', line 12

def empty_line?
  /^\s*$/.match(content) || false
end

#is_comment?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/apfel/line.rb', line 68

def is_comment?
 whole_comment? || open_comment? || close_comment? || in_comment
end

#keyObject



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

Returns:

  • (Boolean)


40
41
42
# File 'lib/apfel/line.rb', line 40

def key_value_pair?
  !!(/^\s*"([^"]+)"\s*=/.match(content))
end

#open_commentObject



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

def open_comment
  /^\/\*(.+)$/.match(content).to_s
end

#open_comment?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/apfel/line.rb', line 28

def open_comment?
  !(open_comment.empty?)
end

#valid?Boolean

Returns:

  • (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

#valueObject



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_commentObject



16
17
18
# File 'lib/apfel/line.rb', line 16

def whole_comment
  /((^\/\*(.+)\*\/)|(^\/\/(.+)))/.match(content).to_s
end

#whole_comment?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/apfel/line.rb', line 20

def whole_comment?
  !(whole_comment.empty?)
end