Class: Gloo::Persist::LineSplitter
- Inherits:
-
Object
- Object
- Gloo::Persist::LineSplitter
- Defined in:
- lib/gloo/persist/line_splitter.rb
Constant Summary collapse
- BEGIN_BLOCK =
'BEGIN'.freeze
- END_BLOCK =
'END'.freeze
Instance Attribute Summary collapse
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
Instance Method Summary collapse
-
#detect_name ⇒ Object
Detect the object name.
-
#detect_type ⇒ Object
Detect the object type.
-
#detect_value ⇒ Object
Detect the object value.
-
#initialize(line, tabs) ⇒ LineSplitter
constructor
Set up a line splitter.
-
#split ⇒ Object
Split the line into 3 parts.
Constructor Details
#initialize(line, tabs) ⇒ LineSplitter
Set up a line splitter
20 21 22 23 |
# File 'lib/gloo/persist/line_splitter.rb', line 20 def initialize( line, tabs ) @line = line @tabs = tabs end |
Instance Attribute Details
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
15 16 17 |
# File 'lib/gloo/persist/line_splitter.rb', line 15 def obj @obj end |
Instance Method Details
#detect_name ⇒ Object
Detect the object name.
39 40 41 42 43 |
# File 'lib/gloo/persist/line_splitter.rb', line 39 def detect_name @line = @line.strip @idx = @line.index( ' ' ) @name = @line[ 0..@idx - 1 ] end |
#detect_type ⇒ Object
Detect the object type.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gloo/persist/line_splitter.rb', line 48 def detect_type @line = @line[ @idx + 1..-1 ] @idx = @line.index( ' ' ) if @line[ 0 ] == ':' @type = 'untyped' return end @type = @line[ 0..( @idx ? @idx - 1 : -1 ) ] @type = @type[ 1..-1 ] if @type[ 0 ] == '[' @type = @type[ 0..-2 ] if @type[ -1 ] == ']' end |
#detect_value ⇒ Object
Detect the object value. Use nil if there is no value specified.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gloo/persist/line_splitter.rb', line 66 def detect_value if @idx @value = @line[ @idx + 1..-1 ] if @value[ 0..1 ] == ': ' @value = @value[ 2..-1 ] elsif @value[ 0 ] == ':' @value = @value[ 1..-1 ] end else @value = nil end end |
#split ⇒ Object
Split the line into 3 parts.
28 29 30 31 32 33 34 |
# File 'lib/gloo/persist/line_splitter.rb', line 28 def split detect_name detect_type detect_value return @name, @type, @value end |