Class: Germinate::Selector
- Inherits:
-
Object
- Object
- Germinate::Selector
- Defined in:
- lib/germinate/selector.rb
Constant Summary collapse
- PATTERN =
/([@$])?(\w+)?(:([^\s\|]+))?(\|([\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.
-
#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
- #end_offset_for_slice ⇒ Object
-
#initialize(string, default_key) ⇒ Selector
constructor
A new instance of Selector.
- #start_offset_for_slice ⇒ Object
Constructor Details
#initialize(string, default_key) ⇒ Selector
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/germinate/selector.rb', line 15 def initialize(string, default_key) @string = string @default_key = default_key match_data = case string when "", nil then {} else PATTERN.match(string) end @selector_type = case match_data[1] when "$" then :special when "@", nil then :code else raise "Unknown selector type '#{match_data[1]}'" end @key = match_data[2] || default_key if match_data[3] parse_excerpt(match_data[3]) else @delimiter = '..' @start_offset = 1 @end_offset = -1 @length = nil end @pipeline = String(match_data[6]).split("|") 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 |
#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
#end_offset_for_slice ⇒ Object
45 46 47 |
# File 'lib/germinate/selector.rb', line 45 def end_offset_for_slice offset_for_slice(end_offset) end |
#start_offset_for_slice ⇒ Object
41 42 43 |
# File 'lib/germinate/selector.rb', line 41 def start_offset_for_slice offset_for_slice(start_offset) end |