power-hours 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a05edfaea3aaf3667bfc1c6281827524f34cea6c924bb3bbaefe5c1cff53dd3d
4
- data.tar.gz: c0d73bd22938295b7cdc86134d4e55ce1e52566f500e5e1320d4f5daec6371fc
3
+ metadata.gz: 0b7abf414bd625d97cb500eb50473aa1eb463dbcf9fa7deef14b2210deb94339
4
+ data.tar.gz: 416922f35b5c9fb6f9f52df49c812666fc24b974a154d8c0f5783ca4f7668665
5
5
  SHA512:
6
- metadata.gz: a93d5ffd74e36026ea4e72702181655751aa6d42aa9319ce922f1809f2be06f756db8dadaaef251983aa4e3cc563b818bf9805ea8e7967e6db4280fe4f003f1c
7
- data.tar.gz: 3494d1052057bf5ecabb2bb70f0d15ef38c52132c5acb18cf9865af943c3eedcaf6ad2dfb1306db8a93a744bbc6572798c1cae56cb0ad349fe8c79469c6f26de
6
+ metadata.gz: 2525e9bed0d4ffc2a9e259d69de72baeb8768cd6bf0a724d25a42b212641cc45ad9ff91a8bad68d2f8609e282f613f6cbdfef32b53bddd3c6a7df54fca50da02
7
+ data.tar.gz: d396c887f117715df01cf8a384ea9900c5e499a67d3cc87f03725f8712c49788414ebc1eb043e8a290e56b4866ef72a6bbd15f7daf96eea860a40e03e2fec1e7
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_model"
4
+ require "json"
4
5
 
5
6
  module OpeningHours
6
7
  class Type < ActiveModel::Type::Value
@@ -30,6 +31,8 @@ module OpeningHours
30
31
  schedule
31
32
  in Hash => hash
32
33
  OpeningHours::Schedule.build(hash)
34
+ in String => string if (hash = hash_from_json_string(string))
35
+ OpeningHours::Schedule.build(hash)
33
36
  in candidate if (hash = hash_from(candidate))
34
37
  OpeningHours::Schedule.build(hash)
35
38
  else
@@ -43,5 +46,12 @@ module OpeningHours
43
46
  hash = value.to_h
44
47
  hash if hash.is_a?(Hash)
45
48
  end
49
+
50
+ def hash_from_json_string(value)
51
+ parsed = JSON.parse(value)
52
+ parsed if parsed.is_a?(Hash)
53
+ rescue JSON::ParserError
54
+ nil
55
+ end
46
56
  end
47
57
  end
@@ -1,3 +1,3 @@
1
1
  module OpeningHours
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power-hours
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Melchert