Class: LucidWorks::Elevation
- Inherits:
-
Object
- Object
- LucidWorks::Elevation
- Extended by:
- ActiveModel::Naming, SimpleNaming
- Includes:
- ActiveModel::Conversion
- Defined in:
- lib/lucid_works/elevation.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#doc_id ⇒ Object
readonly
Returns the value of attribute doc_id.
-
#excluded ⇒ Object
(also: #excluded?)
readonly
Returns the value of attribute excluded.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #destroy ⇒ Object
- #first? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Elevation
constructor
A new instance of Elevation.
- #last? ⇒ Boolean
- #move_down ⇒ Object
- #move_up ⇒ Object
- #persisted? ⇒ Boolean
- #save ⇒ Object
Methods included from SimpleNaming
Constructor Details
#initialize(attributes = {}) ⇒ Elevation
Returns a new instance of Elevation.
16 17 18 19 20 21 22 23 |
# File 'lib/lucid_works/elevation.rb', line 16 def initialize(attributes = {}) @doc_id = attributes[:doc_id] @collection = attributes[:collection] @query = attributes[:query] @excluded = [true, "true"].include? attributes[:excluded] @persisted = [true, "true"].include? attributes[:persisted] @id = "#{CGI.escape query}~~#{doc_id}" end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
13 14 15 |
# File 'lib/lucid_works/elevation.rb', line 13 def collection @collection end |
#doc_id ⇒ Object (readonly)
Returns the value of attribute doc_id.
13 14 15 |
# File 'lib/lucid_works/elevation.rb', line 13 def doc_id @doc_id end |
#excluded ⇒ Object (readonly) Also known as: excluded?
Returns the value of attribute excluded.
13 14 15 |
# File 'lib/lucid_works/elevation.rb', line 13 def excluded @excluded end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/lucid_works/elevation.rb', line 13 def id @id end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
13 14 15 |
# File 'lib/lucid_works/elevation.rb', line 13 def query @query end |
Instance Method Details
#destroy ⇒ Object
38 39 40 41 42 43 |
# File 'lib/lucid_works/elevation.rb', line 38 def destroy return unless settings.elevations.include?(query) settings.elevations[query].delete_if {|elevation| "#{CGI.escape query}~~#{elevation['doc']}" == id } settings.elevations.delete(query) if settings.elevations[query].empty? settings.save end |
#first? ⇒ Boolean
45 46 47 |
# File 'lib/lucid_works/elevation.rb', line 45 def first? index_of_in_elevations(doc_id) == 0 end |
#last? ⇒ Boolean
49 50 51 |
# File 'lib/lucid_works/elevation.rb', line 49 def last? index_of_in_elevations(doc_id) == elevations.size - 1 end |
#move_down ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/lucid_works/elevation.rb', line 61 def move_down return if last? current_index = index_of_in_settings(doc_id) new_index = elevation_indexes[elevation_indexes.index(current_index) + 1] settings.elevations[query].move(current_index, new_index) settings.save end |
#move_up ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/lucid_works/elevation.rb', line 53 def move_up return if first? current_index = index_of_in_settings(doc_id) new_index = elevation_indexes[elevation_indexes.index(current_index) - 1] settings.elevations[query].move(current_index, new_index) settings.save end |
#persisted? ⇒ Boolean
34 35 36 |
# File 'lib/lucid_works/elevation.rb', line 34 def persisted? @persisted end |
#save ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/lucid_works/elevation.rb', line 25 def save settings.elevations[query] ||= [] settings.elevations[query] << {'doc' => doc_id, 'exclude' => excluded?} settings.save @persisted = true rescue false end |