Module: Radio5::Utils
Constant Summary
Constants included
from Constants
Constants::ASSET_HOST, Constants::DECADES, Constants::IMAGE_SIZES, Constants::MAX_PAGE_SIZE, Constants::MOODS, Constants::MOODS_MAPPING, Constants::USER_TRACK_STATUSES, Constants::USER_TRACK_STATUSES_MAPPING
Class Method Summary
collapse
Class Method Details
.create_asset_url(path, filename) ⇒ Object
37
38
39
|
# File 'lib/radio5/utils.rb', line 37
def create_asset_url(path, filename)
URI.join(ASSET_HOST, path, filename).to_s
end
|
.normalize_string(string) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/radio5/utils.rb', line 49
def normalize_string(string)
return if string.nil? || string.empty?
normalized = string.strip
normalized unless normalized.empty?
end
|
.parse_asset_url(node) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/radio5/utils.rb', line 30
def parse_asset_url(node)
if node
path, filename = node.fetch_values(:path, :filename)
create_asset_url(path, filename)
end
end
|
.parse_image_urls(node, entity:) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/radio5/utils.rb', line 16
def parse_image_urls(node, entity:)
if node
path, filename = node.fetch_values(:path, :filename)
image_sizes = IMAGE_SIZES.fetch(entity)
image_sizes.each_with_object({}) do |image_size, hash|
image_size_path = "#{path}#{image_size}/"
image_url = create_asset_url(image_size_path, filename)
hash[image_size] = image_url
end
end
end
|
.parse_json(json_raw) ⇒ Object
12
13
14
|
# File 'lib/radio5/utils.rb', line 12
def parse_json(json_raw)
JSON.parse(json_raw, symbolize_names: true)
end
|
.parse_time_string(time_string) ⇒ Object
41
42
43
|
# File 'lib/radio5/utils.rb', line 41
def parse_time_string(time_string)
Time.parse(time_string).utc
end
|
.parse_unix_timestamp(ts) ⇒ Object
45
46
47
|
# File 'lib/radio5/utils.rb', line 45
def parse_unix_timestamp(ts)
Time.at(ts).utc
end
|
.stringify_moods(moods) ⇒ Object
56
57
58
|
# File 'lib/radio5/utils.rb', line 56
def stringify_moods(moods)
moods.map { |mood| MOODS_MAPPING.fetch(mood) }
end
|
.stringify_user_track_status(status) ⇒ Object
.symbolize_mood(mood) ⇒ Object
60
61
62
|
# File 'lib/radio5/utils.rb', line 60
def symbolize_mood(mood)
MOODS_MAPPING.key(mood)
end
|
.symbolize_user_track_status(status) ⇒ Object