Class: Germinate::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/germinate/selector.rb

Constant Summary collapse

PATTERN =
/([@$])?(\w+)?(:([^\s\|]+))?(\|([\w|]+))?/
EXCERPT_PATTERN =
%r{((-?\d+)|(/[^/]*/))(((\.\.\.?)|(,))((-?\d+)|(/[^/]*/)))?}

Instance Attribute Summary collapse

Instance Method Summary collapse

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_keyObject (readonly)

Returns the value of attribute default_key.



10
11
12
# File 'lib/germinate/selector.rb', line 10

def default_key
  @default_key
end

#delimiterObject (readonly)

Returns the value of attribute delimiter.



8
9
10
# File 'lib/germinate/selector.rb', line 8

def delimiter
  @delimiter
end

#end_offsetObject (readonly)

Returns the value of attribute end_offset.



6
7
8
# File 'lib/germinate/selector.rb', line 6

def end_offset
  @end_offset
end

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/germinate/selector.rb', line 4

def key
  @key
end

#lengthObject (readonly)

Returns the value of attribute length.



7
8
9
# File 'lib/germinate/selector.rb', line 7

def length
  @length
end

#pipelineObject (readonly)

Returns the value of attribute pipeline.



9
10
11
# File 'lib/germinate/selector.rb', line 9

def pipeline
  @pipeline
end

#selector_typeObject (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_offsetObject (readonly)

Returns the value of attribute start_offset.



5
6
7
# File 'lib/germinate/selector.rb', line 5

def start_offset
  @start_offset
end

#stringObject (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_sliceObject



45
46
47
# File 'lib/germinate/selector.rb', line 45

def end_offset_for_slice
  offset_for_slice(end_offset)
end

#start_offset_for_sliceObject



41
42
43
# File 'lib/germinate/selector.rb', line 41

def start_offset_for_slice
  offset_for_slice(start_offset)
end