Class: SpreeCmCommissioner::Integrations::StadiumXV1::Resources::Match

Inherits:
Base
  • Object
show all
Defined in:
app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_collection

Constructor Details

#initialize(attributes = {}) ⇒ Match

Returns a new instance of Match.



29
30
31
32
33
34
35
36
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 29

def initialize(attributes = {})
  super(attributes)

  @on_sale = attributes['on_sale'] != false
  @is_ended = attributes['is_ended'] == true || attributes['is_ended'] == 'true'
  @allow_predition = attributes['allow_predition'] == true || attributes['allow_predition'] == 'true'
  @league = League.new(attributes['league']) if attributes['league'].is_a?(Hash)
end

Instance Attribute Details

#_idObject

Returns the value of attribute _id.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def _id
  @_id
end

#allow_preditionObject

Returns the value of attribute allow_predition.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def allow_predition
  @allow_predition
end

#away_logoObject

Returns the value of attribute away_logo.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def 
  @away_logo
end

#away_nameObject

Returns the value of attribute away_name.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def away_name
  @away_name
end

#away_scoreObject

Returns the value of attribute away_score.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def away_score
  @away_score
end

#club_idObject

Returns the value of attribute club_id.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def club_id
  @club_id
end

#created_byObject

Returns the value of attribute created_by.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def created_by
  @created_by
end

#dateObject

Returns the value of attribute date.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def date
  @date
end

#discount_ticketObject

Returns the value of attribute discount_ticket.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def discount_ticket
  @discount_ticket
end

#fileObject

Returns the value of attribute file.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def file
  @file
end

#home_logoObject

Returns the value of attribute home_logo.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def 
  @home_logo
end

#home_nameObject

Returns the value of attribute home_name.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def home_name
  @home_name
end

#home_scoreObject

Returns the value of attribute home_score.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def home_score
  @home_score
end

#is_endedObject

Returns the value of attribute is_ended.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def is_ended
  @is_ended
end

#leagueObject

Returns the value of attribute league.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def league
  @league
end

#league_idObject

Returns the value of attribute league_id.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def league_id
  @league_id
end

#on_saleObject

Returns the value of attribute on_sale.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def on_sale
  @on_sale
end

#posterObject

Returns the value of attribute poster.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def poster
  @poster
end

#promotionObject

Returns the value of attribute promotion.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def promotion
  @promotion
end

#stadiumObject

Returns the value of attribute stadium.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def stadium
  @stadium
end

#timeObject

Returns the value of attribute time.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def time
  @time
end

#updated_byObject

Returns the value of attribute updated_by.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def updated_by
  @updated_by
end

#weekObject

Returns the value of attribute week.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def week
  @week
end

#zonesObject

Returns the value of attribute zones.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 4

def zones
  @zones
end

Instance Method Details

#display_match_datetimeObject



53
54
55
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 53

def display_match_datetime
  match_datetime&.strftime('%B %d, %Y at %I:%M %p')
end

#match_datetimeObject



57
58
59
60
61
62
63
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 57

def match_datetime
  return nil unless @date && @time

  Time.zone.parse("#{@date} #{@time}")
rescue StandardError
  nil
end

#meta_descriptionObject



44
45
46
47
48
49
50
51
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 44

def meta_description
  return nil if home_name.blank? || away_name.blank?

  location = stadium.present? ? " at #{stadium}" : ''
  league_info = league&.name.present? ? " - #{league.name}" : ''

  "#{home_name} vs #{away_name}#{league_info} on #{display_match_datetime}#{location}. Book tickets now!"
end

#meta_titleObject



38
39
40
41
42
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 38

def meta_title
  return nil if home_name.blank? || away_name.blank?

  "#{home_name} vs #{away_name} - #{display_match_datetime}"
end

#to_hObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/match.rb', line 65

def to_h
  {
    _id: _id,
    home_name: home_name,
    home_logo: ,
    away_name: away_name,
    away_logo: ,
    home_score: home_score,
    away_score: away_score,
    date: date,
    time: time,
    stadium: stadium,
    week: week,
    league_id: league_id,
    club_id: club_id,
    discount_ticket: discount_ticket,
    on_sale: on_sale,
    is_ended: is_ended,
    allow_predition: allow_predition,
    file: file,
    created_by: created_by,
    updated_by: updated_by,
    zones: zones&.map(&:to_h),
    promotion: promotion,
    poster: poster,
    league: league&.to_h
  }.compact
end