crafterm-comma 0.1.7 → 0.1.8
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.
- data/lib/comma/extractors.rb +14 -10
- metadata +2 -2
data/lib/comma/extractors.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Comma
|
2
|
-
|
2
|
+
|
3
3
|
class Extractor
|
4
4
|
|
5
5
|
def initialize(instance, &block)
|
@@ -7,18 +7,22 @@ module Comma
|
|
7
7
|
@block = block
|
8
8
|
@results = []
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def results
|
12
12
|
instance_eval &@block
|
13
13
|
@results
|
14
14
|
end
|
15
|
+
|
16
|
+
def id
|
17
|
+
method_missing(:id)
|
18
|
+
end
|
15
19
|
end
|
16
|
-
|
20
|
+
|
17
21
|
class HeaderExtractor < Extractor
|
18
|
-
|
22
|
+
|
19
23
|
def method_missing(sym, *args, &block)
|
20
24
|
@results << sym.to_s.humanize if args.blank?
|
21
|
-
|
25
|
+
|
22
26
|
args.each do |arg|
|
23
27
|
case arg
|
24
28
|
when Hash
|
@@ -35,20 +39,20 @@ module Comma
|
|
35
39
|
end
|
36
40
|
end
|
37
41
|
end
|
38
|
-
|
42
|
+
|
39
43
|
class DataExtractor < Extractor
|
40
|
-
|
44
|
+
|
41
45
|
def method_missing(sym, *args, &block)
|
42
46
|
@results << @instance.send(sym).to_s if args.blank?
|
43
|
-
|
47
|
+
|
44
48
|
args.each do |arg|
|
45
49
|
case arg
|
46
50
|
when Hash
|
47
51
|
arg.each do |k, v|
|
48
|
-
@results << @instance.send(sym).send(k).to_s
|
52
|
+
@results << (@instance.send(sym).nil? ? '' : @instance.send(sym).send(k).to_s )
|
49
53
|
end
|
50
54
|
when Symbol
|
51
|
-
|
55
|
+
@results << ( @instance.send(sym).nil? ? '' : @instance.send(sym).send(arg).to_s )
|
52
56
|
when String
|
53
57
|
@results << @instance.send(sym).to_s
|
54
58
|
else
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crafterm-comma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcus Crafter
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|