Class: FCC::Station::RecordDelegate
- Inherits:
-
Object
- Object
- FCC::Station::RecordDelegate
show all
- Defined in:
- lib/fcc/station/record_delegate.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of RecordDelegate.
6
7
8
|
# File 'lib/fcc/station/record_delegate.rb', line 6
def initialize(result)
@result = result
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/fcc/station/record_delegate.rb', line 10
def method_missing(m, *args, &block)
return find_result(@result, m) unless @result.is_a?(Array)
return find_result(@result.first, m) if @result.size == 1
filtered_results = @result.filter { |result|
result[:status] == 'LIC' }
filtered_results = filtered_results.collect { |res|
find_result(res, m)
}.uniq
filtered_results.size == 1 ? filtered_results.first : filtered_results
end
|
Instance Method Details
83
84
85
86
87
88
|
# File 'lib/fcc/station/record_delegate.rb', line 83
def
@community ||= begin
= Community.new(city: || city, state: || state, country: country)
if .to_h.compact.any?
end
end
|
90
91
92
93
94
95
96
97
98
|
# File 'lib/fcc/station/record_delegate.rb', line 90
def contact
contact = main_studio_contact
return unless contact
@contact ||= begin
contact = Contact.new(name: contact['contactName'], title: contact['contactTitle'], address: contact['contactAddress1'], address2: contact['contactAddress2'], city: contact['contactCity'], state: contact['contactState'], zip_code: contact['contactZip'], phone: contact['contactPhone'], fax: contact['contactFax'], email: contact['contactEmail'], website: contact['contactWebsite'])
contact if contact.to_h.compact.any?
end
end
|
#frequency ⇒ Object
54
55
56
|
# File 'lib/fcc/station/record_delegate.rb', line 54
def frequency
super&.to_f
end
|
#has_data? ⇒ Boolean
46
47
48
|
# File 'lib/fcc/station/record_delegate.rb', line 46
def has_data?
@result.present?
end
|
#id ⇒ Object
50
51
52
|
# File 'lib/fcc/station/record_delegate.rb', line 50
def id
super || send(:fcc_id)
end
|
#inspect ⇒ Object
100
101
102
|
# File 'lib/fcc/station/record_delegate.rb', line 100
def inspect
"<RecordDelegate:[#{band}] #{frequency} #{call_sign} — #{.city} #{.state} />"
end
|
#operating_hours ⇒ Object
62
63
64
|
# File 'lib/fcc/station/record_delegate.rb', line 62
def operating_hours
super&.downcase
end
|
#owner ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/fcc/station/record_delegate.rb', line 66
def owner
@owner ||= begin
contact = Contact.new(
name: party_name || licensed_to,
address: party_address_1,
address2: party_address_2,
city: (party_city || city),
state: (party_state || state),
zip_code: party_zip_1,
country: country,
phone: party_phone
)
contact if contact.to_h.compact.any?
end
end
|
#rf_channel ⇒ Object
58
59
60
|
# File 'lib/fcc/station/record_delegate.rb', line 58
def rf_channel
super || send(:channel)
end
|
#to_json ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/fcc/station/record_delegate.rb', line 25
def to_json
return {}.tap do |record|
[Station::Result::EXTENDED_ATTRIBUTES | Station::Result::BASIC_ATTRIBUTES].flatten.each do |attr|
record[attr.to_sym] = send(attr.to_sym)
end
%i[contact owner community].each do |attr|
result = send(attr.to_sym)
next unless result
record[attr] ||= if result.is_a?(Struct)
result.to_h.compact
elsif result.is_a?(Array) && result.compact.size > 0
result
elsif result.present?
result.to_s
end
end
end
end
|