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 +4 -4
- data/lib/parsable/context.rb +2 -2
- data/lib/parsable/remote.rb +1 -1
- data/lib/parsable/version.rb +1 -1
- data/spec/context_spec.rb +33 -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: 7dbda0cdf2f7beade2e6df252c90b65d4ac58b17
|
4
|
+
data.tar.gz: 7d14957ad92713946d32d44383c17bfac1be6c5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad2d59f720cec99c17891b69a62f03b3199f916d5bb7e0e9e7d6b3c24a92ece2a2584756958193761419cc0f778fad53ba446ada7e67b8436df11f565abec124
|
7
|
+
data.tar.gz: 6c777d157984a1ed707e453513dfc9b7ecb65a8cdef6db1c2fa3a6bf5ae9510f56b6b0739db950c2111babbcbb2c9619c1ee8cb4d41d6ee655492eb3a7ccdd2b
|
data/lib/parsable/context.rb
CHANGED
@@ -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 =>
|
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
|
})
|
data/lib/parsable/remote.rb
CHANGED
@@ -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.
|
26
|
+
http.timeout = 2
|
27
27
|
http.on_success { |easy| @body = easy.body_str }
|
28
28
|
end
|
29
29
|
rescue Curl::Err::CurlError
|
data/lib/parsable/version.rb
CHANGED
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(
|
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.
|
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-
|
11
|
+
date: 2016-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|