Class: Pcut::Query
- Inherits:
-
Object
- Object
- Pcut::Query
- Defined in:
- lib/pcut/query.rb
Constant Summary collapse
- FORMAT =
%r{\A\s*\[\s*/\\?(.)/\s*,\s*([0-9\-]+)\s*\]\z}
Instance Attribute Summary collapse
-
#delimiter ⇒ Object
Returns the value of attribute delimiter.
-
#index ⇒ Object
Returns the value of attribute index.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(delimiter, index) ⇒ Query
constructor
A new instance of Query.
- #to_s ⇒ Object
Constructor Details
#initialize(delimiter, index) ⇒ Query
Returns a new instance of Query.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pcut/query.rb', line 12 def initialize(delimiter, index) if !delimiter.is_a?(String) || delimiter.size != 1 raise ArgumentError, "invalid delimiter: #{delimiter}" end if !index.is_a?(Pcut::RangeIndex) raise ArgumentError, "index must be a RangeIndex: #{index}" end @delimiter = delimiter @index = index end |
Instance Attribute Details
#delimiter ⇒ Object
Returns the value of attribute delimiter.
10 11 12 |
# File 'lib/pcut/query.rb', line 10 def delimiter @delimiter end |
#index ⇒ Object
Returns the value of attribute index.
10 11 12 |
# File 'lib/pcut/query.rb', line 10 def index @index end |
Class Method Details
.parse(str) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pcut/query.rb', line 24 def self.parse(str) unless str.is_a?(String) raise ArgumentError, "#{str.to_s} is not a string" end unless str =~ FORMAT raise ArgumentError, "invalid format: #{str}" end index = Pcut::RangeIndex.parse($2) self.new($1, index) end |
Instance Method Details
#to_s ⇒ Object
35 36 37 |
# File 'lib/pcut/query.rb', line 35 def to_s "[/%s/,%s]" % [@delimiter, @index.to_s] end |