Class: Flycal::Mock::Config
- Inherits:
-
Object
- Object
- Flycal::Mock::Config
- Defined in:
- lib/flycal/mock/config.rb
Overview
Resolves mock options from CLI and/or a JSON template under mocks/.
Constant Summary collapse
- TEMPLATE_KEYS =
%w[ mockCalendar mockEventDescriptionPatterns mockEventCount mockEventFrom mockEventTo mockEventDurationMin mockEventDurationMax mockEventHoursFrom mockEventHoursTo mockSeed ].freeze
Instance Attribute Summary collapse
-
#calendar_name ⇒ Object
readonly
Returns the value of attribute calendar_name.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#duration_max_seconds ⇒ Object
readonly
Returns the value of attribute duration_max_seconds.
-
#duration_min_seconds ⇒ Object
readonly
Returns the value of attribute duration_min_seconds.
-
#hours_from ⇒ Object
readonly
Returns the value of attribute hours_from.
-
#hours_to ⇒ Object
readonly
Returns the value of attribute hours_to.
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
-
#range_from ⇒ Object
readonly
Returns the value of attribute range_from.
-
#range_to ⇒ Object
readonly
Returns the value of attribute range_to.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#seed ⇒ Object
readonly
Returns the value of attribute seed.
-
#template_name ⇒ Object
readonly
Returns the value of attribute template_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Config
constructor
A new instance of Config.
- #to_h ⇒ Object
Constructor Details
#initialize(options) ⇒ Config
Returns a new instance of Config.
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 |
# File 'lib/flycal/mock/config.rb', line 34 def initialize() merged = load_template([:mockTemplate]) TEMPLATE_KEYS.each do |key| sym = key.to_sym value = [sym] next if value.nil? || value.to_s.empty? merged[key] = value end @template_name = [:mockTemplate].to_s.empty? ? nil : [:mockTemplate].to_s calendar = merged["mockCalendar"].to_s calendar = [:mockCalendar].to_s if calendar.empty? @calendar_name = calendar raise Flycal::Error, "Mock mode requires mockCalendar in the template (or --mockCalendar)." if @calendar_name.empty? @raw = merged @patterns = split_patterns(merged["mockEventDescriptionPatterns"]) @count = Integer(merged["mockEventCount"]) @range_from = parse_date(merged["mockEventFrom"], end_of_day: false) @range_to = parse_date(merged["mockEventTo"], end_of_day: true) @duration_min_seconds = DurationParser.to_seconds(merged["mockEventDurationMin"].to_s) @duration_max_seconds = DurationParser.to_seconds(merged["mockEventDurationMax"].to_s) @hours_from = parse_hour_minute(merged["mockEventHoursFrom"]) @hours_to = parse_hour_minute(merged["mockEventHoursTo"]) @seed = resolve_seed(merged["mockSeed"]) validate! end |
Instance Attribute Details
#calendar_name ⇒ Object (readonly)
Returns the value of attribute calendar_name.
22 23 24 |
# File 'lib/flycal/mock/config.rb', line 22 def calendar_name @calendar_name end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
22 23 24 |
# File 'lib/flycal/mock/config.rb', line 22 def count @count end |
#duration_max_seconds ⇒ Object (readonly)
Returns the value of attribute duration_max_seconds.
22 23 24 |
# File 'lib/flycal/mock/config.rb', line 22 def duration_max_seconds @duration_max_seconds end |
#duration_min_seconds ⇒ Object (readonly)
Returns the value of attribute duration_min_seconds.
22 23 24 |
# File 'lib/flycal/mock/config.rb', line 22 def duration_min_seconds @duration_min_seconds end |
#hours_from ⇒ Object (readonly)
Returns the value of attribute hours_from.
22 23 24 |
# File 'lib/flycal/mock/config.rb', line 22 def hours_from @hours_from end |
#hours_to ⇒ Object (readonly)
Returns the value of attribute hours_to.
22 23 24 |
# File 'lib/flycal/mock/config.rb', line 22 def hours_to @hours_to end |
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
22 23 24 |
# File 'lib/flycal/mock/config.rb', line 22 def patterns @patterns end |
#range_from ⇒ Object (readonly)
Returns the value of attribute range_from.
22 23 24 |
# File 'lib/flycal/mock/config.rb', line 22 def range_from @range_from end |
#range_to ⇒ Object (readonly)
Returns the value of attribute range_to.
22 23 24 |
# File 'lib/flycal/mock/config.rb', line 22 def range_to @range_to end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
22 23 24 |
# File 'lib/flycal/mock/config.rb', line 22 def raw @raw end |
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
22 23 24 |
# File 'lib/flycal/mock/config.rb', line 22 def seed @seed end |
#template_name ⇒ Object (readonly)
Returns the value of attribute template_name.
22 23 24 |
# File 'lib/flycal/mock/config.rb', line 22 def template_name @template_name end |
Class Method Details
.enabled?(options) ⇒ Boolean
26 27 28 |
# File 'lib/flycal/mock/config.rb', line 26 def self.enabled?() ![:mockTemplate].to_s.empty? || ![:mockCalendar].to_s.empty? end |
.from_options(options) ⇒ Object
30 31 32 |
# File 'lib/flycal/mock/config.rb', line 30 def self.() new() end |
Instance Method Details
#to_h ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/flycal/mock/config.rb', line 65 def to_h { mock_calendar: calendar_name, mock_seed: seed, mock_template: template_name, mock_event_description_patterns: patterns.join(","), mock_event_count: count, mock_event_from: range_from, mock_event_to: range_to, mock_event_duration_min: duration_min_seconds, mock_event_duration_max: duration_max_seconds, mock_event_hours_from: hours_from, mock_event_hours_to: hours_to } end |