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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +2 -0
- data/lib/stockboy.rb +2 -0
- data/lib/stockboy/providers/file.rb +1 -1
- data/lib/stockboy/translations/date.rb +17 -1
- data/lib/stockboy/translations/uk_date.rb +4 -16
- data/lib/stockboy/translations/us_date.rb +7 -13
- data/lib/stockboy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9f39ab2f4181e4a6bc9856318ae586c1ad63502
|
4
|
+
data.tar.gz: d182b13648a082b1adf6a50a9c4c96c208f33501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4037153d318abe04dcd6aa2abfbe5c15e3c7ea7658b3f72bdefccf201f5092aecf94f4f2cf680421c75d75e12467608bac8aa8c3c293001959e560f30b880272
|
7
|
+
data.tar.gz: 74f16a90d396df9f7c4cea5f7ae67319553bbd577001c4dce6417a63569095fb2cfefc067c6b74d6305fb9d8c922f4ec3408e9a61b1d8198dae081ee9ce87d7c
|
data/CHANGELOG.md
CHANGED
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
|
@@ -30,12 +30,28 @@ module Stockboy::Translations
|
|
30
30
|
return nil if value.blank?
|
31
31
|
|
32
32
|
case value
|
33
|
-
when ::String then
|
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::
|
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
|
43
|
-
|
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::
|
29
|
+
class USDate < Stockboy::Translations::Date
|
30
|
+
|
31
|
+
private
|
29
32
|
|
30
33
|
# @return [Date]
|
31
34
|
#
|
32
|
-
def
|
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
|
43
|
-
|
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
|
data/lib/stockboy/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2013-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|