Class: Cql
- Inherits:
-
Object
- Object
- Cql
- Defined in:
- lib/enju_biblio/porta_cql.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#logic ⇒ Object
readonly
Returns the value of attribute logic.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#sort_by ⇒ Object
readonly
Returns the value of attribute sort_by.
-
#until ⇒ Object
readonly
Returns the value of attribute until.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(line) ⇒ Cql
constructor
A new instance of Cql.
- #split_clause_text(line) ⇒ Object
- #to_sunspot ⇒ Object
Constructor Details
#initialize(line) ⇒ Cql
Returns a new instance of Cql.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/enju_biblio/porta_cql.rb', line 8 def initialize(line) @logic = nil @query = split_clause_text(line).collect{|txt| Clause.new(txt)} from_day, @query = extract_with_index(@query, /from/io) @from = comp_date(from_day) until_day, @query = extract_with_index(@query, /until/io) @until = comp_date(until_day) sort_by, @query = extract_with_index(@query, /sortBy/io) @sort_by = sort_by ? sort_by.terms.first : '' end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
20 21 22 |
# File 'lib/enju_biblio/porta_cql.rb', line 20 def from @from end |
#logic ⇒ Object (readonly)
Returns the value of attribute logic.
20 21 22 |
# File 'lib/enju_biblio/porta_cql.rb', line 20 def logic @logic end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
20 21 22 |
# File 'lib/enju_biblio/porta_cql.rb', line 20 def query @query end |
#sort_by ⇒ Object (readonly)
Returns the value of attribute sort_by.
20 21 22 |
# File 'lib/enju_biblio/porta_cql.rb', line 20 def sort_by @sort_by end |
#until ⇒ Object (readonly)
Returns the value of attribute until.
20 21 22 |
# File 'lib/enju_biblio/porta_cql.rb', line 20 def until @until end |
Instance Method Details
#==(other) ⇒ Object
22 23 24 25 26 |
# File 'lib/enju_biblio/porta_cql.rb', line 22 def ==(other) instance_variables.all? do |val| instance_variable_get(val) == other.instance_variable_get(val) end end |
#split_clause_text(line) ⇒ Object
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 58 |
# File 'lib/enju_biblio/porta_cql.rb', line 32 def split_clause_text(line) clauses = [] s = StringScanner.new(line) text = '' while s.rest? case when s.scan(/\s+/) text << s.matched when s.scan(/"(?:[^"\\]|\\.)*"/) text << s.matched when s.scan(/(AND|OR)/i) logic = s.matched.upcase if @logic raise QuerySyntaxError unless @logic == logic else @logic = logic end clauses << text.strip text = '' when s.scan(/\S*/) text << s.matched end end clauses << text.strip clauses.collect{|txt| txt.gsub(/(\A\(|\)\Z)/, '')} end |
#to_sunspot ⇒ Object
28 29 30 |
# File 'lib/enju_biblio/porta_cql.rb', line 28 def to_sunspot (@query.collect{|c| c.to_sunspot} + date_range(@from, @until)).join(" #{@logic} ") end |