stockboy 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f4c7e5f39621bb22f09bd06f634cb49023d6d6c
4
- data.tar.gz: 0bc7683c74a66cc5a9510cde44c2ed15a62a64e7
3
+ metadata.gz: e9f39ab2f4181e4a6bc9856318ae586c1ad63502
4
+ data.tar.gz: d182b13648a082b1adf6a50a9c4c96c208f33501
5
5
  SHA512:
6
- metadata.gz: 92b3a6d076053c21f48df30fbd544bf2ac952b9fd336a4080466e1b190a632216fc07f59f64756c79238a6304d84fb49e182f1119e6ed1e85376991b4e08cb9d
7
- data.tar.gz: cc0a187e65ed56537ca104d23a42a359d064cae1aa6378605d4c60fb4b7c810956a6997f14518f6d710732f8ff4de393be5766bbe3426abad8ca76b985069d16
6
+ metadata.gz: 4037153d318abe04dcd6aa2abfbe5c15e3c7ea7658b3f72bdefccf201f5092aecf94f4f2cf680421c75d75e12467608bac8aa8c3c293001959e560f30b880272
7
+ data.tar.gz: 74f16a90d396df9f7c4cea5f7ae67319553bbd577001c4dce6417a63569095fb2cfefc067c6b74d6305fb9d8c922f4ec3408e9a61b1d8198dae081ee9ce87d7c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.2 / 2013-12-04
4
+
5
+ [BUGFIX] Registered :string translation that was missed
6
+ [BUGFIX] All date translators handle String / Date / Time correctly
7
+
3
8
  ## 0.5.1 / 2013-12-03
4
9
 
5
10
  [ENHANCEMENT] Link to full documentation and license
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Stockboy
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/stockboy.png)][gem]
3
4
  [![Build Status](https://travis-ci.org/avit/stockboy.png)][travis]
4
5
  [![Code Climate](https://codeclimate.com/github/avit/stockboy.png)][climate]
5
6
 
@@ -317,3 +318,4 @@ Contributions and pull requests are welcome.
317
318
  [travis]: https://travis-ci.org/avit/stockboy
318
319
  [climate]: https://codeclimate.com/github/avit/stockboy
319
320
  [rdoc]: http://rdoc.info/gems/stockboy/frames
321
+ [gem]: http://rubygems.org/gems/stockboy
data/lib/stockboy.rb CHANGED
@@ -15,6 +15,7 @@ require 'stockboy/translations/default_false'
15
15
  require 'stockboy/translations/default_true'
16
16
  require 'stockboy/translations/default_nil'
17
17
  require 'stockboy/translations/default_zero'
18
+ require 'stockboy/translations/string'
18
19
  require 'stockboy/translations/boolean'
19
20
  require 'stockboy/translations/integer'
20
21
  require 'stockboy/translations/decimal'
@@ -66,6 +67,7 @@ module Stockboy
66
67
  register :or_nil, DefaultNil
67
68
  register :or_empty, DefaultEmptyString
68
69
  register :or_zero, DefaultZero
70
+ register :string, String
69
71
  register :boolean, Boolean
70
72
  register :integer, Integer
71
73
  register :decimal, Decimal
@@ -63,7 +63,7 @@ module Stockboy::Providers
63
63
  when String
64
64
  Dir[::File.join(file_dir, file_name)]
65
65
  end
66
- @matching_file = pick_from(files) if files.any?
66
+ @matching_file = pick_from(files.sort) if files.any?
67
67
  end
68
68
 
69
69
  def clear
@@ -30,12 +30,28 @@ module Stockboy::Translations
30
30
  return nil if value.blank?
31
31
 
32
32
  case value
33
- when ::String then ::Date.parse(value)
33
+ when ::String then parse_date(value.strip)
34
34
  when ::Time, ::DateTime then ::Date.new(value.year, value.month, value.day)
35
35
  when ::Date then value
36
36
  else nil
37
37
  end
38
38
  end
39
39
 
40
+ private
41
+
42
+ # Generic parse action, overridden by subclasses
43
+ # @return [Date]
44
+ #
45
+ def parse_date(value)
46
+ ::Date.parse(value)
47
+ end
48
+
49
+ def separator(value)
50
+ value.include?(?/) ? ?/ : ?-
51
+ end
52
+
53
+ # Match date strings with 2-digit year
54
+ MATCH_YYYY = %r"\A\d{1,2}(/|-)\d{1,2}\1\d{4}\z"
55
+
40
56
  end
41
57
  end
@@ -1,4 +1,5 @@
1
1
  require 'stockboy/translator'
2
+ require 'stockboy/translations/us_date'
2
3
 
3
4
  module Stockboy::Translations
4
5
 
@@ -25,26 +26,13 @@ module Stockboy::Translations
25
26
  # record.check_in = "1/2/12"
26
27
  # date.translate(record, :check_in) # => #<Date 2012-02-01>
27
28
  #
28
- class UKDate < Stockboy::Translator
29
-
30
- # @return [Date]
31
- #
32
- def translate(context)
33
- value = field_value(context, field_key)
34
- return nil if value.blank?
35
-
36
- ::Date.strptime(value, date_format(value))
37
- end
29
+ class UKDate < Stockboy::Translations::USDate
38
30
 
39
31
  private
40
32
 
41
33
  def date_format(value)
42
- x = value.include?(?/) ? ?/ : ?-
43
- if value =~ %r"\d{1,2}(?:/|-)\d{1,2}(?:/|-)\d{2}$"
44
- "%d#{x}%m#{x}%y"
45
- else
46
- "%d#{x}%m#{x}%Y"
47
- end
34
+ x = separator(value)
35
+ value =~ MATCH_YYYY ? "%d#{x}%m#{x}%Y" : "%d#{x}%m#{x}%y"
48
36
  end
49
37
 
50
38
  end
@@ -1,4 +1,5 @@
1
1
  require 'stockboy/translator'
2
+ require 'stockboy/translations/date'
2
3
 
3
4
  module Stockboy::Translations
4
5
 
@@ -25,26 +26,19 @@ module Stockboy::Translations
25
26
  # record.check_in = "2-1-12"
26
27
  # date.translate(record, :check_in) # => #<Date 2012-02-01>
27
28
  #
28
- class USDate < Stockboy::Translator
29
+ class USDate < Stockboy::Translations::Date
30
+
31
+ private
29
32
 
30
33
  # @return [Date]
31
34
  #
32
- def translate(context)
33
- value = field_value(context, field_key)
34
- return nil if value.blank?
35
-
35
+ def parse_date(value)
36
36
  ::Date.strptime(value, date_format(value))
37
37
  end
38
38
 
39
- private
40
-
41
39
  def date_format(value)
42
- x = value.include?(?/) ? ?/ : ?-
43
- if value =~ %r"\d{1,2}(?:/|-)\d{1,2}(?:/|-)\d{4}"
44
- "%m#{x}%d#{x}%Y"
45
- else
46
- "%m#{x}%d#{x}%y"
47
- end
40
+ x = separator(value)
41
+ value =~ MATCH_YYYY ? "%m#{x}%d#{x}%Y" : "%m#{x}%d#{x}%y"
48
42
  end
49
43
 
50
44
  end
@@ -1,3 +1,3 @@
1
1
  module Stockboy
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stockboy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Vit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-03 00:00:00.000000000 Z
11
+ date: 2013-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake