Class: Germinate::Selector
- Inherits:
-
Object
- Object
- Germinate::Selector
- Defined in:
- lib/germinate/selector.rb
Constant Summary collapse
- PATTERN =
/^([@$])?(\w+)?(:([^\|]+))?(\|([\w|]+))?$/
- EXCERPT_OUTPUT_PATTERN =
/^([@$])?(\w+)?(\|([\w|]+))?(:([^\|]+))?$/
- EXCERPT_PATTERN =
%r{((-?\d+)|(/[^/]*/))(((\.\.\.?)|(,))((-?\d+)|(/[^/]*/)))?}
Instance Attribute Summary collapse
-
#default_key ⇒ Object
readonly
Returns the value of attribute default_key.
-
#delimiter ⇒ Object
readonly
Returns the value of attribute delimiter.
-
#end_offset ⇒ Object
readonly
Returns the value of attribute end_offset.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
-
#pipeline ⇒ Object
readonly
Returns the value of attribute pipeline.
-
#selector_type ⇒ Object
readonly
Returns the value of attribute selector_type.
-
#start_offset ⇒ Object
readonly
Returns the value of attribute start_offset.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #end_offset_for_slice ⇒ Object
-
#excerpt_output? ⇒ Boolean
Should excerpting be done on the output of the process?.
-
#initialize(string, default_key = :unspecified, origin = "<Unknown>") ⇒ Selector
constructor
A new instance of Selector.
-
#slice? ⇒ Boolean
Is it just a subset of the source hunk? (opposite of @whole?).
- #start_offset_for_slice ⇒ Object
- #to_s ⇒ Object
-
#whole? ⇒ Boolean
Is it the entire hunk? (opposite of #slice?).
Constructor Details
#initialize(string, default_key = :unspecified, origin = "<Unknown>") ⇒ Selector
Returns a new instance of Selector.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/germinate/selector.rb', line 17 def initialize(string, default_key=:unspecified, origin="<Unknown>") @string = string @default_key = default_key @origin = origin match_data = case string when "", nil then {} else if data = PATTERN.match(string) @excerpt_output = false elsif data = EXCERPT_OUTPUT_PATTERN.match(string) @excerpt_output = true else raise "Could not parse selector '#{string}'" end data end subscript_index = @excerpt_output ? 6 : 3 pipeline_index = @excerpt_output ? 4 : 6 @selector_type = case match_data[1] when "$" then :special when "@" then :code when nil then default_key == :unspecified ? :special : :code else raise "Unknown selector type '#{match_data[1]}'" end @key = match_data[2] || (default_key == :unspecified ? "SOURCE" : default_key) if match_data[subscript_index] @slice = true parse_excerpt(match_data[subscript_index]) else @slice = false @delimiter = '..' @start_offset = 1 @end_offset = -1 @length = nil end @pipeline = String(match_data[pipeline_index]). split("|").unshift('_transform').uniq end |
Instance Attribute Details
#default_key ⇒ Object (readonly)
Returns the value of attribute default_key.
10 11 12 |
# File 'lib/germinate/selector.rb', line 10 def default_key @default_key end |
#delimiter ⇒ Object (readonly)
Returns the value of attribute delimiter.
8 9 10 |
# File 'lib/germinate/selector.rb', line 8 def delimiter @delimiter end |
#end_offset ⇒ Object (readonly)
Returns the value of attribute end_offset.
6 7 8 |
# File 'lib/germinate/selector.rb', line 6 def end_offset @end_offset end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/germinate/selector.rb', line 4 def key @key end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
7 8 9 |
# File 'lib/germinate/selector.rb', line 7 def length @length end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
11 12 13 |
# File 'lib/germinate/selector.rb', line 11 def origin @origin end |
#pipeline ⇒ Object (readonly)
Returns the value of attribute pipeline.
9 10 11 |
# File 'lib/germinate/selector.rb', line 9 def pipeline @pipeline end |
#selector_type ⇒ Object (readonly)
Returns the value of attribute selector_type.
3 4 5 |
# File 'lib/germinate/selector.rb', line 3 def selector_type @selector_type end |
#start_offset ⇒ Object (readonly)
Returns the value of attribute start_offset.
5 6 7 |
# File 'lib/germinate/selector.rb', line 5 def start_offset @start_offset end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
2 3 4 |
# File 'lib/germinate/selector.rb', line 2 def string @string end |
Instance Method Details
#==(other) ⇒ Object
86 87 88 |
# File 'lib/germinate/selector.rb', line 86 def ==(other) string == other end |
#end_offset_for_slice ⇒ Object
63 64 65 |
# File 'lib/germinate/selector.rb', line 63 def end_offset_for_slice offset_for_slice(end_offset) end |
#excerpt_output? ⇒ Boolean
Should excerpting be done on the output of the process?
68 69 70 |
# File 'lib/germinate/selector.rb', line 68 def excerpt_output? @excerpt_output end |
#slice? ⇒ Boolean
Is it just a subset of the source hunk? (opposite of @whole?)
73 74 75 |
# File 'lib/germinate/selector.rb', line 73 def slice? @slice && !@excerpt_output end |
#start_offset_for_slice ⇒ Object
59 60 61 |
# File 'lib/germinate/selector.rb', line 59 def start_offset_for_slice offset_for_slice(start_offset) end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/germinate/selector.rb', line 82 def to_s string + "(#{origin})" end |
#whole? ⇒ Boolean
Is it the entire hunk? (opposite of #slice?)
78 79 80 |
# File 'lib/germinate/selector.rb', line 78 def whole? !slice? end |