Class: GoogleMapsPlatform::PlaceOpeningHours

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/google_maps_platform/models/place_opening_hours.rb

Overview

An object describing the opening hours of a place.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(open_now: SKIP, periods: SKIP, special_days: SKIP, type: SKIP, weekday_text: SKIP, additional_properties: nil) ⇒ PlaceOpeningHours

Returns a new instance of PlaceOpeningHours.



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/google_maps_platform/models/place_opening_hours.rb', line 64

def initialize(open_now: SKIP, periods: SKIP, special_days: SKIP,
               type: SKIP, weekday_text: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @open_now = open_now unless open_now == SKIP
  @periods = periods unless periods == SKIP
  @special_days = special_days unless special_days == SKIP
  @type = type unless type == SKIP
  @weekday_text = weekday_text unless weekday_text == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#open_nowTrueClass | FalseClass

A boolean value indicating if the place is open at the current time.

Returns:

  • (TrueClass | FalseClass)


14
15
16
# File 'lib/google_maps_platform/models/place_opening_hours.rb', line 14

def open_now
  @open_now
end

#periodsArray[PlaceOpeningHoursPeriod]

An array of opening periods covering seven days, starting from Sunday, in chronological order.

Returns:



19
20
21
# File 'lib/google_maps_platform/models/place_opening_hours.rb', line 19

def periods
  @periods
end

#special_daysArray[PlaceSpecialDay]

An array of up to seven entries corresponding to the next seven days.

Returns:



23
24
25
# File 'lib/google_maps_platform/models/place_opening_hours.rb', line 23

def special_days
  @special_days
end

#typeString

A type string used to identify the type of secondary hours (for example, DRIVE_THROUGH, HAPPY_HOUR, DELIVERY, TAKEOUT, KITCHEN, BREAKFAST, LUNCH, DINNER, BRUNCH, PICKUP, SENIOR_HOURS). Set for secondary_opening_hours only.

Returns:

  • (String)


30
31
32
# File 'lib/google_maps_platform/models/place_opening_hours.rb', line 30

def type
  @type
end

#weekday_textArray[String]

An array of strings describing in human-readable text the hours of the place.

Returns:

  • (Array[String])


35
36
37
# File 'lib/google_maps_platform/models/place_opening_hours.rb', line 35

def weekday_text
  @weekday_text
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/google_maps_platform/models/place_opening_hours.rb', line 78

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  open_now = hash.key?('open_now') ? hash['open_now'] : SKIP
  # Parameter is an array, so we need to iterate through it
  periods = nil
  unless hash['periods'].nil?
    periods = []
    hash['periods'].each do |structure|
      periods << (PlaceOpeningHoursPeriod.from_hash(structure) if structure)
    end
  end

  periods = SKIP unless hash.key?('periods')
  # Parameter is an array, so we need to iterate through it
  special_days = nil
  unless hash['special_days'].nil?
    special_days = []
    hash['special_days'].each do |structure|
      special_days << (PlaceSpecialDay.from_hash(structure) if structure)
    end
  end

  special_days = SKIP unless hash.key?('special_days')
  type = hash.key?('type') ? hash['type'] : SKIP
  weekday_text = hash.key?('weekday_text') ? hash['weekday_text'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  PlaceOpeningHours.new(open_now: open_now,
                        periods: periods,
                        special_days: special_days,
                        type: type,
                        weekday_text: weekday_text,
                        additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



38
39
40
41
42
43
44
45
46
# File 'lib/google_maps_platform/models/place_opening_hours.rb', line 38

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['open_now'] = 'open_now'
  @_hash['periods'] = 'periods'
  @_hash['special_days'] = 'special_days'
  @_hash['type'] = 'type'
  @_hash['weekday_text'] = 'weekday_text'
  @_hash
end

.nullablesObject

An array for nullable fields



60
61
62
# File 'lib/google_maps_platform/models/place_opening_hours.rb', line 60

def self.nullables
  []
end

.optionalsObject

An array for optional fields



49
50
51
52
53
54
55
56
57
# File 'lib/google_maps_platform/models/place_opening_hours.rb', line 49

def self.optionals
  %w[
    open_now
    periods
    special_days
    type
    weekday_text
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



131
132
133
134
135
136
# File 'lib/google_maps_platform/models/place_opening_hours.rb', line 131

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} open_now: #{@open_now.inspect}, periods: #{@periods.inspect}, special_days:"\
  " #{@special_days.inspect}, type: #{@type.inspect}, weekday_text: #{@weekday_text.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



123
124
125
126
127
128
# File 'lib/google_maps_platform/models/place_opening_hours.rb', line 123

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} open_now: #{@open_now}, periods: #{@periods}, special_days:"\
  " #{@special_days}, type: #{@type}, weekday_text: #{@weekday_text}, additional_properties:"\
  " #{@additional_properties}>"
end