parsable 0.2.3 → 0.2.4

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
  SHA1:
3
- metadata.gz: 18cce76ed8ffa27c2806d615761493dd6a7ccfb7
4
- data.tar.gz: 790da170e48c431062195b4d10603d2d4e3273a9
3
+ metadata.gz: 7dbda0cdf2f7beade2e6df252c90b65d4ac58b17
4
+ data.tar.gz: 7d14957ad92713946d32d44383c17bfac1be6c5b
5
5
  SHA512:
6
- metadata.gz: 14e336799890ced0d93ce27b790fd44ceacc19829a09d52d0f7366c69ccbce6cb215a00cc93aade672bac046fa4fc02721850c50e4a363583cb3d660eecee7db
7
- data.tar.gz: 0bd620754b6effcd1bfc9ceb07b56f019c26127551458fd6148c5db4d05865ddd0b5c43130f89c7b5e7ed8e8852afd93d91368ea48fc540221b4bd7756d34e0f
6
+ metadata.gz: ad2d59f720cec99c17891b69a62f03b3199f916d5bb7e0e9e7d6b3c24a92ece2a2584756958193761419cc0f778fad53ba446ada7e67b8436df11f565abec124
7
+ data.tar.gz: 6c777d157984a1ed707e453513dfc9b7ecb65a8cdef6db1c2fa3a6bf5ae9510f56b6b0739db950c2111babbcbb2c9619c1ee8cb4d41d6ee655492eb3a7ccdd2b
@@ -8,10 +8,10 @@ module Parsable
8
8
  attr_accessor :variables
9
9
 
10
10
  def initialize args={}
11
-
11
+ today = Date.today
12
12
  @variables = args.fetch(:variables, {
13
13
  :random => OpenStruct.new(:hex => SecureRandom.hex, :integer => Time.now.to_i),
14
- :date => OpenStruct.new(:today => Date.today.to_s, :year => Date.today.year.to_s),
14
+ :date => OpenStruct.new(:today => today.to_s, :year => today.year.to_s, :month => sprintf('%02d', today.month), :day => sprintf('%02d', today.day)),
15
15
  :time => OpenStruct.new(:now => Time.now.to_s),
16
16
  :custom => OpenStruct.new
17
17
  })
@@ -23,7 +23,7 @@ module Parsable
23
23
  begin
24
24
  Curl::Easy.perform(url) do |http|
25
25
  headers.each { |header, value| http.headers[header] = value }
26
- http.connect_timeout = 2
26
+ http.timeout = 2
27
27
  http.on_success { |easy| @body = easy.body_str }
28
28
  end
29
29
  rescue Curl::Err::CurlError
@@ -1,3 +1,3 @@
1
1
  module Parsable
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
data/spec/context_spec.rb CHANGED
@@ -5,9 +5,41 @@ describe Parsable::Context do
5
5
  let(:context) { Parsable::Context.new }
6
6
 
7
7
  describe '#new' do
8
+ subject { context.instance_variable_get('@variables') }
9
+
8
10
  it "sets default variables" do
9
11
  keys = %i(random date time custom remote sremote)
10
- expect(context.instance_variable_get('@variables').keys).to match_array(keys)
12
+ expect(subject.keys).to match_array(keys)
13
+ end
14
+
15
+ {
16
+ '2016-5-6' => {
17
+ 'date.today' => '2016-05-06',
18
+ 'date.year' => '2016',
19
+ 'date.month' => '05',
20
+ 'date.day' => '06'
21
+ },
22
+ '2016-5-29' => {
23
+ 'date.today' => '2016-05-29',
24
+ 'date.year' => '2016',
25
+ 'date.month' => '05',
26
+ 'date.day' => '29'
27
+ },
28
+ '2016-12-31' => {
29
+ 'date.today' => '2016-12-31',
30
+ 'date.year' => '2016',
31
+ 'date.month' => '12',
32
+ 'date.day' => '31'
33
+ }
34
+
35
+ }.each do |date, examples|
36
+ examples.each do |var, value|
37
+ namespace, varname = var.split('.')
38
+ it "sets #{var}" do
39
+ allow(Date).to receive(:today).and_return(Date.parse(date))
40
+ expect(subject[namespace.to_sym].send(varname)).to eq value
41
+ end
42
+ end
11
43
  end
12
44
  end
13
45
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hubert Liu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-06 00:00:00.000000000 Z
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler