dohutil 0.1.5 → 0.1.6

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.
@@ -14,6 +14,11 @@ class BigDecimal
14
14
  self
15
15
  end
16
16
 
17
+ alias :_doh_original_to_s :to_s
18
+ def to_s(format = 'F')
19
+ _doh_original_to_s(format)
20
+ end
21
+
17
22
  def to_dig(digits_after_decimal = 2)
18
23
  raise ArgumentError.new("digits_after_decimal must be > 0") unless digits_after_decimal > 0
19
24
  return '0.' + ('0' * digits_after_decimal) if nan? || infinite?
@@ -5,11 +5,6 @@ class Date
5
5
  civil(year, month, -1).mday
6
6
  end
7
7
 
8
- undef inspect
9
- def inspect
10
- strftime('%F')
11
- end
12
-
13
8
  def weekday?
14
9
  (wday > 0) && (wday < 6)
15
10
  end
@@ -16,7 +16,7 @@ module MakeTimeLikeDateTime
16
16
  end
17
17
 
18
18
  def prev_second(n = 1)
19
- self + n
19
+ self - n
20
20
  end
21
21
  end
22
22
 
@@ -29,10 +29,6 @@ class DateTime
29
29
  seconds.to_f / DOHRUBY_SECONDS_IN_DAY.to_f
30
30
  end
31
31
 
32
- def inspect
33
- strftime('%F %X')
34
- end
35
-
36
32
  def next_second(n = 1)
37
33
  self + (SECONDS_IN_DAY * n)
38
34
  end
@@ -0,0 +1,26 @@
1
+ require 'date'
2
+ require 'bigdecimal'
3
+
4
+ class Date
5
+ def inspect
6
+ "#<Date:#{strftime('%F')}>"
7
+ end
8
+ end
9
+
10
+ class DateTime
11
+ def inspect
12
+ "#<DateTime:#{strftime('%F %X %z')}>"
13
+ end
14
+ end
15
+
16
+ class Time
17
+ def inspect
18
+ "#<Time:#{strftime('%F %X %z')}>"
19
+ end
20
+ end
21
+
22
+ class BigDecimal
23
+ def inspect
24
+ "#<BigDecimal:#{to_s('F')}>"
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ require 'doh/core_ext/datewithtime'
2
+
3
+ class Date
4
+ def self.utcday
5
+ Time.now.utc.to_date
6
+ end
7
+ end
8
+
9
+ class DateTime
10
+ def self.utcnow
11
+ now.utc
12
+ end
13
+ end
14
+
15
+ class Time
16
+ def self.utcnow
17
+ now.utc
18
+ end
19
+ end
@@ -4,12 +4,12 @@ module Doh
4
4
 
5
5
  @@current_date_objs = []
6
6
 
7
- def self.current_date(dflt = Date.today)
7
+ def self.current_date(dflt = Date.utcday)
8
8
  return dflt if @@current_date_objs.empty?
9
9
  @@current_date_objs.last.to_date
10
10
  end
11
11
 
12
- def self.current_datetime(dflt = DateTime.now.utc)
12
+ def self.current_datetime(dflt = DateTime.utcnow)
13
13
  return dflt if @@current_date_objs.empty?
14
14
  cdo = @@current_date_objs.last
15
15
  return cdo if cdo.respond_to?(:hour)
@@ -42,41 +42,16 @@ class BigDecimal
42
42
  end
43
43
  end
44
44
 
45
- class PhoneDisplayString < String
46
- def to_display
47
- Doh::display_phone(self)
48
- end
49
-
50
- def to_s
51
- self
52
- end
53
- end
54
-
55
- class PostalDisplayString < String
56
- def to_display
57
- Doh::display_postal(self)
58
- end
59
-
60
- def to_s
61
- self
62
- end
63
- end
64
-
65
- class SsnDisplayString < String
66
- def to_display
67
- Doh::display_ssn(self)
68
- end
69
-
70
- def to_s
71
- self
72
- end
73
- end
74
-
75
45
  module Doh
76
46
 
77
- def self.display_phone(str)
47
+ def self.display_phone(str, html_format = false)
78
48
  return str unless str.size == 10
79
- str[0..2] + '-' + str[3..5] + '-' + str[6..9]
49
+ formatted = "#{str[0..2]}-#{str[3..5]}-#{str[6..9]}"
50
+ if html_format
51
+ "<a href='callto:+1#{formatted}'>#{formatted}</a>"
52
+ else
53
+ formatted
54
+ end
80
55
  end
81
56
 
82
57
  def self.display_postal(str)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dohutil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,19 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-02-23 00:00:00.000000000Z
14
- dependencies: []
13
+ date: 2012-03-01 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: dohroot
17
+ requirement: &70300039051680 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.1.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70300039051680
15
26
  description: Tiny utilities, packaged together so they don't each have their own gem.
16
27
  email:
17
28
  - devinfo@atpsoft.com
@@ -26,19 +37,18 @@ files:
26
37
  - lib/doh/class_basename.rb
27
38
  - lib/doh/config.rb
28
39
  - lib/doh/core_ext/bigdecimal.rb
29
- - lib/doh/core_ext/class/force_deep_copy.rb
30
40
  - lib/doh/core_ext/date.rb
31
41
  - lib/doh/core_ext/datewithtime.rb
32
42
  - lib/doh/core_ext/dir.rb
43
+ - lib/doh/core_ext/force_deep_copy.rb
33
44
  - lib/doh/core_ext/hash.rb
45
+ - lib/doh/core_ext/inspect.rb
34
46
  - lib/doh/core_ext/string.rb
47
+ - lib/doh/core_ext/utc.rb
35
48
  - lib/doh/current_date.rb
36
49
  - lib/doh/env.rb
37
- - lib/doh/findup.rb
38
50
  - lib/doh/http_helper.rb
39
51
  - lib/doh/log/stub.rb
40
- - lib/doh/options.rb
41
- - lib/doh/root.rb
42
52
  - lib/doh/to_display.rb
43
53
  - test/test_date.rb
44
54
  - test/test_datewithtime.rb
data/lib/doh/findup.rb DELETED
@@ -1,12 +0,0 @@
1
- module Doh
2
- def self.findup(start_directory, filename, max_tries = 20)
3
- curr_directory = start_directory
4
- max_tries.times do
5
- path = File.expand_path(File.join(curr_directory, filename))
6
- return path if File.exist?(path)
7
- return nil if (path == '/')
8
- curr_directory = File.join(curr_directory, '..')
9
- end
10
- nil
11
- end
12
- end
data/lib/doh/options.rb DELETED
@@ -1,108 +0,0 @@
1
- require 'ostruct'
2
- require 'optparse'
3
-
4
- module Doh
5
-
6
- class Options
7
- # this class is for command line parsing
8
- # the hash is of the form: {'variable_name' => option_list}
9
- # you can also pass an array of hashes [{'var1' => optlist1}, {'var2' => optlist2}]
10
- # if you use an array of hashes, the help will be shown in the order specified (otherwise it's random)
11
-
12
- # option_list is an array, the first element of which is the default value of the option
13
- # the others are of the form with examples shown on
14
- # http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/index.html
15
- # returns any non-options parameters via method varargs
16
- # set allow_unknown_options to true to allow for filename specification, etc..
17
- # if the default value is :required for a field, then if that field isn't
18
- # specified, an exception will be raised
19
- def initialize(param_definition_hash_or_array, allow_unknown_options = false, explanation_text = '', unknown_options_name = 'file', allow_no_prefix = false)
20
- @vals = OpenStruct.new
21
-
22
- @opts = OptionParser.new
23
- @opts.banner = "Usage: #{$0} [options]"
24
- if explanation_text != ''
25
- @opts.separator ""
26
- @opts.separator explanation_text
27
- end
28
- @opts.separator ""
29
- @opts.separator "Specific options:"
30
- @opts.separator ""
31
-
32
- if param_definition_hash_or_array.class == Array
33
- param_definition_array = param_definition_hash_or_array
34
- param_definition_hash = param_definition_hash_or_array.inject({}) {|sum, elem| sum.merge(elem)}
35
- else
36
- param_definition_array = param_definition_hash_or_array.collect {|elem1, elem2| {elem1 => elem2}}
37
- param_definition_hash = param_definition_hash_or_array
38
- end
39
-
40
- param_definition_array.each do |elem|
41
- keyname = elem.to_a[0][1][2]
42
- if keyname =~ /^--no-/
43
- raise "key name: #{keyname} will not behave as desired if meant to be a boolean, rename it, or pass in allow_no_prefix flag as 5th param"
44
- end
45
- end
46
-
47
- param_definition_array.each do |elem|
48
- key = elem.to_a[0][0]
49
- val = elem.to_a[0][1]
50
- default = val.shift
51
- @vals.send("#{key}=", default)
52
- val.last.insert(0, '(required) - ') if val.last.is_a?(String) && default == :required
53
- @opts.on(*val) do |optval|
54
- @vals.send("#{key}=", optval)
55
- end
56
- end
57
-
58
- @opts.separator ""
59
- @opts.separator "Common options:"
60
- @opts.separator ""
61
-
62
- @opts.on("-h", "-?", "--help", "Show this message") do
63
- puts @opts
64
- exit
65
- end
66
-
67
- varargs = []
68
- @opts.order(ARGV) do |arg|
69
- varargs.push(arg)
70
- end
71
- @vals.varargs = varargs
72
-
73
- unset_vars = []
74
- param_definition_hash.each do |key,val|
75
- if @vals.send(key) == :required
76
- unset_vars.push(key)
77
- end
78
- end
79
-
80
- exception = ''
81
- exception << "Required options not specified: #{unset_vars.inspect}\n" unless unset_vars.size == 0
82
- exception << "Unknown options specified: #{varargs.inspect}\n" unless allow_unknown_options || (varargs.size == 0)
83
- exception << "You must specify #{allow_unknown_options} #{unknown_options_name}#{allow_unknown_options > 1 ? 's' : ''}" if allow_unknown_options.class == Fixnum && varargs.size != allow_unknown_options
84
- if allow_unknown_options.class == Range
85
- if (allow_unknown_options.min == allow_unknown_options.max)
86
- if (varargs.size < allow_unknown_options.min)
87
- exception << "You must specify at least #{allow_unknown_options.min} #{unknown_options_name}#{allow_unknown_options.min > 1 ? 's' : ''}"
88
- end
89
- elsif !allow_unknown_options.include?(varargs.size)
90
- exception << "You must specify between #{allow_unknown_options.min} and #{allow_unknown_options.max} #{unknown_options_name}s"
91
- end
92
- end
93
- if exception != ''
94
- puts @opts
95
- raise exception
96
- end
97
- end
98
-
99
- def method_missing(sym, *args)
100
- @vals.send(sym, *args)
101
- end
102
-
103
- def to_s
104
- @opts.to_s
105
- end
106
- end
107
-
108
- end
data/lib/doh/root.rb DELETED
@@ -1,40 +0,0 @@
1
- require 'doh/findup'
2
-
3
- module Doh
4
- def self.root
5
- @root
6
- end
7
-
8
- def self.root=(directory)
9
- @root = directory
10
- libdir = File.join(@root, 'lib')
11
- $LOAD_PATH.push(libdir) if libdir
12
- end
13
-
14
- def self.find_root(start_directory, filename = 'dohroot', max_tries = 20)
15
- rootfile = Doh::findup(start_directory, filename, max_tries)
16
- if rootfile
17
- Doh::root = File.dirname(rootfile)
18
- end
19
- end
20
-
21
- def self.find_root_from_file(filepath = nil)
22
- Doh::find_root(File.dirname(filepath || caller[0]))
23
- end
24
-
25
- def self.find_root_from_path(path)
26
- if File.directory?(path)
27
- Doh::find_root(path)
28
- else
29
- Doh::find_root(File.dirname(path))
30
- end
31
- end
32
-
33
- def self.find_root_from_prog
34
- Doh::find_root(File.dirname($PROGRAM_NAME))
35
- end
36
-
37
- def self.find_root_from_pwd
38
- Doh::find_root(Dir.pwd)
39
- end
40
- end