Class: Locomotive::WuBook::CheckIntervalTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Locomotive::WuBook::CheckIntervalTag
- Includes:
- PluginHelper
- Defined in:
- lib/locomotive/wubook/plugin/check_interval_tag.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens, context) ⇒ CheckIntervalTag
constructor
A new instance of CheckIntervalTag.
- #render(context) ⇒ Object
- #render_disabled(context) ⇒ Object
Methods included from PluginHelper
#fetch_room_base_data, #fetch_room_id, #request_room_data
Constructor Details
#initialize(tag_name, markup, tokens, context) ⇒ CheckIntervalTag
Returns a new instance of CheckIntervalTag.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/locomotive/wubook/plugin/check_interval_tag.rb', line 11 def initialize(tag_name, markup, tokens, context) = { room_ident: '', date_start: '', date_end: '' } markup.scan(::Liquid::TagAttributes) { |key, value| [key.to_sym] = value.gsub(/"|'/, '') } super end |
Instance Method Details
#render(context) ⇒ Object
22 23 24 25 26 27 28 29 30 31 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 59 60 61 62 63 64 65 66 |
# File 'lib/locomotive/wubook/plugin/check_interval_tag.rb', line 22 def render(context) @plugin_obj = context.registers[:plugin_object] config = @plugin_obj.config # Evaluate variables and use the return of the evaluation if it exists.. raise "Missing parameter 'room_ident'" if [:room_ident].empty? room_ident_evaluated = context[[:room_ident]] [:room_ident] = room_ident_evaluated unless room_ident_evaluated.nil? || room_ident_evaluated.empty? ::Locomotive.log "**> CheckIntervalTag room_ident: #{@options[:room_ident]}" raise "Missing parameter 'date_start'" if [:date_start].empty? date_start_evaluated = context[[:date_start]] [:date_start] = date_start_evaluated unless date_start_evaluated.nil? ::Locomotive.log "**> CheckIntervalTag date_start_evaluated: #{@options[:date_start]}" raise "Missing parameter 'date_end'" if [:date_end].empty? date_end_evaluated = context[[:date_end]] [:date_end] = date_end_evaluated unless date_end_evaluated.nil? ::Locomotive.log "**> CheckIntervalTag date_end: #{@options[:date_end]}" start_day = [:date_start] last_day = [:date_end] ::Locomotive.log "**> CheckIntervalTag: Date Interval: #{start_day} - #{last_day}" # Last day is the day of departure. It will not be marked/handled as booked last_day -= 1 ::Locomotive.log "**> Effective end-day: #{last_day} " wired = Wired.new(config) wired.aquire_token room_data = request_room_data(wired, config['lcode'], [:room_ident], start_day, last_day) wired.release_token # Now check the (modified) interval regarding availability is_available = true room_data.each do |data| ::Locomotive.log "**> CheckIntervalTag: check: #{data}" if data['avail'] === 0 then is_available = false; break end end is_available ? "Ok" : "Err" end |
#render_disabled(context) ⇒ Object
68 69 70 |
# File 'lib/locomotive/wubook/plugin/check_interval_tag.rb', line 68 def render_disabled(context) "Ok" end |