hellobase 0.1.7 → 0.1.8

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: 304e4c01b7cf2cda1aba0913505df28995211698b290be7891e3f5f9cbc0825b
4
- data.tar.gz: d20143c56281095365ee8ce07ad3694b9cbba20efda82c84e00fa45647f4b17d
3
+ metadata.gz: 46694043401a358a06c4d8cc43fed3e74ddf49e756da77bf3e501f5368d587a1
4
+ data.tar.gz: 425faddf86643febe8bed91dd8d8da3e44806f6279f57f7a4a40b690112f811b
5
5
  SHA512:
6
- metadata.gz: d8f5f6e09df8dc8529b3194d666b7cc4d085c9eb0210c7787890e0654cb30c76088869c1cfe733d41d3d0949b3a4ab509bc01cd09768a00e2a47124f7865347b
7
- data.tar.gz: 5526a08028b78ad53985d38167a0772c277cd62e5314c39f924035783b8171c714d7ee79563d149533b687fc6e1eca7fb0076183612bd86058b9346e6ad65bd7
6
+ metadata.gz: 87c87f82adc496b5126a32a373998521c79dd61a45111323c5247c78064921873dd7655eb4f26693d57197644813d1d16cbee5ec6d0e99647482d1a96eab6885
7
+ data.tar.gz: 8dfddd47d74040a1edaf77c6e90f24ddb0660a1fc00d5b2fdfe006a201e6973d3c3fb195f403e1196b9fab1c397f9dc3a0c5860110783e304435a28ecc36ec79
@@ -1,32 +1,6 @@
1
- require 'bigdecimal'
2
- require 'date'
3
- require 'active_support/core_ext/date'
4
- require 'active_support/core_ext/time'
5
- require 'active_support/duration'
6
- require 'tod'
7
-
8
- require 'hellobase/array_access'
9
- require 'hellobase/date_creation'
10
- require 'hellobase/datetime_creation'
11
- require 'hellobase/divide_by_zero'
12
- require 'hellobase/duration_arithmetic'
13
- require 'hellobase/string_access'
14
- require 'hellobase/time_creation'
1
+ require 'hellobase/core_ext'
2
+ require 'hellobase/formtastic'
3
+ require 'hellobase/time_zones'
15
4
 
16
5
  module Hellobase
17
- DATE_FORMAT = /^\d{4}-\d{2}-\d{2}$/
18
- TIME_FORMAT = /^\d{2}:\d{2}:\d{2}$/
19
- DATETIME_FORMAT = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} UTC$/
20
-
21
- class Error < StandardError
22
- attr_reader :type, :object
23
-
24
- def initialize(type, object, *args)
25
- @type = type
26
- @object = object
27
- @args = args
28
-
29
- super "#{type}: #{object.inspect}, #{args.inspect}"
30
- end
31
- end
32
6
  end
@@ -0,0 +1,32 @@
1
+ require 'bigdecimal'
2
+ require 'date'
3
+ require 'active_support/core_ext/date'
4
+ require 'active_support/core_ext/time'
5
+ require 'active_support/duration'
6
+ require 'tod'
7
+
8
+ require 'hellobase/core_ext/array_access'
9
+ require 'hellobase/core_ext/date_creation'
10
+ require 'hellobase/core_ext/datetime_creation'
11
+ require 'hellobase/core_ext/divide_by_zero'
12
+ require 'hellobase/core_ext/duration_arithmetic'
13
+ require 'hellobase/core_ext/string_access'
14
+ require 'hellobase/core_ext/time_creation'
15
+
16
+ module Hellobase
17
+ DATE_FORMAT = /^\d{4}-\d{2}-\d{2}$/
18
+ TIME_FORMAT = /^\d{2}:\d{2}:\d{2}$/
19
+ DATETIME_FORMAT = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} UTC$/
20
+
21
+ class Error < StandardError
22
+ attr_reader :type, :object
23
+
24
+ def initialize(type, object, *args)
25
+ @type = type
26
+ @object = object
27
+ @args = args
28
+
29
+ super "#{type}: #{object.inspect}, #{args.inspect}"
30
+ end
31
+ end
32
+ end
@@ -1,7 +1,7 @@
1
1
  Date.singleton_class.prepend(
2
2
  Module.new do
3
3
  def parse(string)
4
- raise Hellobase::Error.new(:date_format, nil, string) unless string =~ Hellobase::DATE_FORMAT
4
+ raise Hellobase::Error.new(:date_format, nil, string) unless (string =~ Hellobase::DATE_FORMAT) || string.blank?
5
5
 
6
6
  begin
7
7
  super
@@ -1,7 +1,7 @@
1
1
  Time.singleton_class.prepend(
2
2
  Module.new do
3
3
  def parse(string)
4
- raise Hellobase::Error.new(:datetime_format, nil, string) unless string =~ Hellobase::DATETIME_FORMAT
4
+ raise Hellobase::Error.new(:datetime_format, nil, string) unless (string =~ Hellobase::DATETIME_FORMAT) || string.blank?
5
5
 
6
6
  begin
7
7
  super
@@ -19,7 +19,12 @@ Time.singleton_class.prepend(
19
19
  end
20
20
 
21
21
  def new(*args)
22
- raise Hellobase::Error.new(:datetime_new, nil)
22
+ # only allow ActiveSupport::TimeZone to use Time.new
23
+ unless caller_locations(1, 1)[0].path.end_with? 'active_support/values/time_zone.rb'
24
+ raise Hellobase::Error.new(:datetime_new, nil)
25
+ end
26
+
27
+ super
23
28
  end
24
29
  end
25
30
  )
@@ -1,7 +1,7 @@
1
1
  Tod::TimeOfDay.singleton_class.prepend(
2
2
  Module.new do
3
3
  def parse(string)
4
- raise Hellobase::Error.new(:time_format, nil, string) unless string =~ Hellobase::TIME_FORMAT
4
+ raise Hellobase::Error.new(:time_format, nil, string) unless (string =~ Hellobase::TIME_FORMAT) || string.blank?
5
5
 
6
6
  begin
7
7
  super
@@ -0,0 +1,6 @@
1
+ require 'active_support' # formtastic needs ActiveSupport::Autoload
2
+ require 'formtastic'
3
+
4
+ require 'hellobase/formtastic/inline_checkbox_input'
5
+ require 'hellobase/formtastic/read_only_input'
6
+ require 'hellobase/formtastic/time_of_day_input'
@@ -0,0 +1,9 @@
1
+ class InlineCheckboxInput < Formtastic::Inputs::BooleanInput
2
+ def to_html
3
+ input_wrapping do
4
+ hidden_field_html <<
5
+ label_html <<
6
+ check_box_html
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ class ReadOnlyInput < ::Formtastic::Inputs::StringInput
2
+ def to_html
3
+ input_wrapping do
4
+ label_html <<
5
+ template.content_tag(:div, options[:content])
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,19 @@
1
+ class TimeOfDayInput < ::Formtastic::Inputs::SelectInput
2
+ def initialize(*)
3
+ super
4
+
5
+ @options[:collection] ||= build_times_collection
6
+ end
7
+
8
+ private
9
+
10
+ def build_times_collection
11
+ hours = 0..23
12
+ minutes = (0..59).select {|m| m % 5 == 0 }
13
+ seconds = (0..59).select {|m| m % 60 == 0 }
14
+ times = hours.map {|h| minutes.map {|m| seconds.map {|s| Tod::TimeOfDay.new(h, m, s) } } }.flatten
15
+
16
+ format = '%I:%M %p'
17
+ times.map {|t| [t.strftime(format), t.to_s] }
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'tzinfo'
2
+
3
+ module Hellobase
4
+ class << self
5
+ def domestic_time_zone_select_values(country_code)
6
+ TZInfo::Country.get(country_code).zone_info.map {|z| [z.description || z.timezone.friendly_identifier(true), z.identifier] }
7
+ end
8
+
9
+ def foreign_time_zone_select_values(country_code)
10
+ TZInfo::Country.all.reject {|c| c.code == country_code }.map(&:zone_info).flatten.uniq.map {|z| [z.description || z.timezone.friendly_identifier(false), z.identifier] }
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Hellobase
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hellobase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Wang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-13 00:00:00.000000000 Z
11
+ date: 2020-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -81,13 +81,19 @@ extra_rdoc_files: []
81
81
  files:
82
82
  - MIT-LICENSE
83
83
  - lib/hellobase.rb
84
- - lib/hellobase/array_access.rb
85
- - lib/hellobase/date_creation.rb
86
- - lib/hellobase/datetime_creation.rb
87
- - lib/hellobase/divide_by_zero.rb
88
- - lib/hellobase/duration_arithmetic.rb
89
- - lib/hellobase/string_access.rb
90
- - lib/hellobase/time_creation.rb
84
+ - lib/hellobase/core_ext.rb
85
+ - lib/hellobase/core_ext/array_access.rb
86
+ - lib/hellobase/core_ext/date_creation.rb
87
+ - lib/hellobase/core_ext/datetime_creation.rb
88
+ - lib/hellobase/core_ext/divide_by_zero.rb
89
+ - lib/hellobase/core_ext/duration_arithmetic.rb
90
+ - lib/hellobase/core_ext/string_access.rb
91
+ - lib/hellobase/core_ext/time_creation.rb
92
+ - lib/hellobase/formtastic.rb
93
+ - lib/hellobase/formtastic/inline_checkbox_input.rb
94
+ - lib/hellobase/formtastic/read_only_input.rb
95
+ - lib/hellobase/formtastic/time_of_day_input.rb
96
+ - lib/hellobase/time_zones.rb
91
97
  - lib/hellobase/version.rb
92
98
  homepage:
93
99
  licenses: []