args_parser 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +7 -0
- data/README.md +5 -6
- data/args_parser.gemspec +1 -0
- data/lib/args_parser.rb +1 -3
- data/lib/args_parser/config.rb +5 -5
- data/lib/args_parser/filter.rb +5 -3
- data/lib/args_parser/main.rb +12 -0
- data/lib/args_parser/parser.rb +38 -46
- data/lib/args_parser/styles/default.rb +1 -1
- data/lib/args_parser/styles/equal.rb +2 -2
- data/lib/args_parser/validator.rb +5 -3
- data/lib/args_parser/version.rb +1 -1
- data/samples/equal_style.rb +18 -0
- data/test/test_args_parser.rb +12 -12
- data/test/test_args_parser_style_equal.rb +12 -12
- data/test/test_default.rb +2 -2
- data/test/test_helper.rb +0 -1
- data/test/test_on.rb +26 -0
- data/test/test_validator.rb +4 -4
- metadata +9 -6
- data/samples/twitter_timeline.rb +0 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8706a4d57149332f2b0483eec8d6c7c90c19f962
|
4
|
+
data.tar.gz: fb8a7fbaf3e694abc577082eaafeaa4f16662f04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd315c4245616b89b3f8494f6d4f35a8869ad3308a9c94a3b4e4411d39627c319aad8c7bce9e8828b418fdb27e4c7491090792486e90266ee524c1013016b866
|
7
|
+
data.tar.gz: f379f7430584f20152ba143072be5b485f1e3dd61c08f87e133a75874f6a142401c68e60f3afb9c0351e4bc8f0354e6d89c0452c7603831e1b7c3d7300895a3d
|
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -7,9 +7,7 @@ args_parser
|
|
7
7
|
|
8
8
|
Requirements
|
9
9
|
------------
|
10
|
-
|
11
|
-
* Ruby 1.9.3+
|
12
|
-
* JRuby 1.6.7+
|
10
|
+
- Ruby 1.8.7 ~ 2.0.0
|
13
11
|
|
14
12
|
|
15
13
|
Install
|
@@ -57,9 +55,10 @@ end
|
|
57
55
|
puts "saved! => #{args[:output]}"
|
58
56
|
```
|
59
57
|
|
60
|
-
equal style
|
58
|
+
### equal style
|
61
59
|
|
62
|
-
% ruby samples/
|
60
|
+
% ruby samples/equal_style.rb --help
|
61
|
+
% ruby samples/equal_style.rb --user=shokai hello world --a=1234
|
63
62
|
|
64
63
|
parse equal style ARGV
|
65
64
|
```ruby
|
@@ -74,7 +73,7 @@ Test
|
|
74
73
|
|
75
74
|
% gem install bundler
|
76
75
|
% bundle install
|
77
|
-
% rake test
|
76
|
+
% bundle exec rake test
|
78
77
|
|
79
78
|
|
80
79
|
Contributing
|
data/args_parser.gemspec
CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.description = %q{Parse/Filter/Validate ARGV from command line with DSL.}
|
11
11
|
gem.summary = gem.description
|
12
12
|
gem.homepage = "http://shokai.github.com/args_parser"
|
13
|
+
gem.license = "MIT"
|
13
14
|
|
14
15
|
gem.files = `git ls-files`.split($/).reject{|i| i=="Gemfile.lock" }
|
15
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/lib/args_parser.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
-
|
1
|
+
require 'args_parser/main'
|
4
2
|
require 'args_parser/parser'
|
5
3
|
require 'args_parser/styles/default'
|
6
4
|
require 'args_parser/styles/equal'
|
data/lib/args_parser/config.rb
CHANGED
data/lib/args_parser/filter.rb
CHANGED
data/lib/args_parser/parser.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
|
2
1
|
module ArgsParser
|
3
|
-
def self.parse(argv=[], config={}, &block)
|
4
|
-
Config.default.each do |k,v|
|
5
|
-
config[k] = v unless config[k]
|
6
|
-
end
|
7
|
-
parser = Parser.new(config, &block)
|
8
|
-
parser.parse argv
|
9
|
-
parser
|
10
|
-
end
|
11
2
|
|
12
3
|
class Parser
|
13
4
|
attr_reader :argv, :params, :aliases
|
@@ -18,9 +9,8 @@ module ArgsParser
|
|
18
9
|
end
|
19
10
|
|
20
11
|
def initialize(config, &block)
|
21
|
-
unless block_given?
|
22
|
-
|
23
|
-
end
|
12
|
+
raise ArgumentError, 'initialize block was not given' unless block_given?
|
13
|
+
|
24
14
|
@config = config
|
25
15
|
@argv = []
|
26
16
|
@params = Hash.new{|h,k|
|
@@ -35,6 +25,7 @@ module ArgsParser
|
|
35
25
|
@aliases = {}
|
36
26
|
@filter = Filter.new
|
37
27
|
@validator = Validator.new
|
28
|
+
@ons = []
|
38
29
|
|
39
30
|
filter do |v|
|
40
31
|
(v.kind_of? String and v =~ /^-?\d+$/) ? v.to_i : v
|
@@ -50,7 +41,7 @@ module ArgsParser
|
|
50
41
|
exit 1
|
51
42
|
end
|
52
43
|
|
53
|
-
instance_eval
|
44
|
+
instance_eval &block
|
54
45
|
end
|
55
46
|
|
56
47
|
private
|
@@ -64,36 +55,43 @@ module ArgsParser
|
|
64
55
|
end
|
65
56
|
|
66
57
|
def filter(name=nil, &block)
|
67
|
-
if block_given?
|
68
|
-
@filter.add name, block
|
69
|
-
end
|
58
|
+
@filter.add name, block if block_given?
|
70
59
|
end
|
71
60
|
|
72
61
|
def on_filter_error(err=nil, name=nil, value=nil, &block)
|
73
62
|
if block_given?
|
74
63
|
@on_filter_error = block
|
75
|
-
|
76
|
-
@on_filter_error.call(err, name, value)
|
64
|
+
elsif @on_filter_error.kind_of? Proc
|
65
|
+
@on_filter_error.call(err, name, value)
|
77
66
|
end
|
78
67
|
end
|
79
68
|
|
80
69
|
def validate(name, message, &block)
|
81
|
-
if block_given?
|
82
|
-
@validator.add name, message, block
|
83
|
-
end
|
70
|
+
@validator.add name, message, block if block_given?
|
84
71
|
end
|
85
72
|
|
86
73
|
def on_validate_error(err=nil, name=nil, value=nil, &block)
|
87
74
|
if block_given?
|
88
75
|
@on_validate_error = block
|
76
|
+
elsif @on_validate_error.kind_of? Proc
|
77
|
+
@on_validate_error.call(err, name, value)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def on(name, &block)
|
82
|
+
name = name.to_sym
|
83
|
+
if block_given?
|
84
|
+
@ons.push :name => name, :callback => block
|
89
85
|
else
|
90
|
-
@
|
86
|
+
@ons.each do |event|
|
87
|
+
event[:callback].call(self[name]) if event[:name] == name
|
88
|
+
end
|
91
89
|
end
|
92
90
|
end
|
93
91
|
|
94
92
|
def default(key)
|
95
93
|
d = params[key.to_sym][:default]
|
96
|
-
|
94
|
+
d.kind_of?(Proc) ? d.call : d
|
97
95
|
end
|
98
96
|
|
99
97
|
public
|
@@ -102,7 +100,7 @@ module ArgsParser
|
|
102
100
|
end
|
103
101
|
|
104
102
|
def parse(argv)
|
105
|
-
|
103
|
+
send "parse_style_#{@config[:style]}", argv
|
106
104
|
params.each do |name, param|
|
107
105
|
next if [nil, true].include? param[:value]
|
108
106
|
begin
|
@@ -119,27 +117,25 @@ module ArgsParser
|
|
119
117
|
on_validate_error ValidationError.new(msg), name, param[:value]
|
120
118
|
end
|
121
119
|
end
|
120
|
+
params.keys.each do |name|
|
121
|
+
on name if has_option? name or has_param? name
|
122
|
+
end
|
122
123
|
end
|
123
124
|
|
124
125
|
def [](key)
|
125
|
-
params[key.to_sym][:value]
|
126
|
+
params[key.to_sym][:value] || default(key)
|
126
127
|
end
|
127
128
|
|
128
129
|
def []=(key, value)
|
129
130
|
params[key.to_sym][:value] = value
|
130
131
|
end
|
131
132
|
|
132
|
-
def has_option?(*
|
133
|
-
!
|
134
|
-
self[i] == true
|
135
|
-
}.include? false)
|
133
|
+
def has_option?(*opts)
|
134
|
+
!opts.flatten.find{|i| self[i] != true}
|
136
135
|
end
|
137
136
|
|
138
|
-
def has_param?(*
|
139
|
-
!
|
140
|
-
v = self[i]
|
141
|
-
(v != nil and v != true) ? true : false
|
142
|
-
}.include? false)
|
137
|
+
def has_param?(*params)
|
138
|
+
!params.flatten.find{|i| self[i] == nil or self[i] == true }
|
143
139
|
end
|
144
140
|
|
145
141
|
def inspect
|
@@ -154,24 +150,20 @@ module ArgsParser
|
|
154
150
|
params_ = Array.new
|
155
151
|
params.each do |k,v|
|
156
152
|
v[:name] = k
|
157
|
-
params_
|
153
|
+
params_.push v
|
158
154
|
end
|
159
|
-
params_ = params_.
|
160
|
-
i[:index] < 0
|
161
|
-
}.sort{|a,b|
|
162
|
-
a[:index] <=> b[:index]
|
163
|
-
}
|
155
|
+
params_ = params_.reject{|i| i[:index] < 0 }.sort{|a,b| a[:index] <=> b[:index] }
|
164
156
|
|
165
157
|
len = params_.map{|i|
|
166
|
-
|
167
|
-
|
168
|
-
|
158
|
+
(i[:alias] ?
|
159
|
+
" -#{i[:name]} (-#{i[:alias]})" :
|
160
|
+
" -#{i[:name]}").size
|
169
161
|
}.max
|
170
162
|
|
171
163
|
"options:\n" + params_.map{|i|
|
172
|
-
line =
|
173
|
-
|
174
|
-
|
164
|
+
line = (i[:alias] ?
|
165
|
+
" -#{i[:name]} (-#{i[:alias]})" :
|
166
|
+
" -#{i[:name]}").ljust(len+2)
|
175
167
|
line += i[:description].to_s
|
176
168
|
line += " : default - #{default i[:name]}" if i[:default]
|
177
169
|
line
|
@@ -12,11 +12,11 @@ module ArgsParser
|
|
12
12
|
is_param = /^-+([^-=\s]+)=(.+)$/
|
13
13
|
argv.each_with_index do |arg, i|
|
14
14
|
if arg =~ is_option
|
15
|
-
k,v =
|
15
|
+
k,v = arg.scan(is_option)[0][0], true
|
16
16
|
elsif arg =~ is_param
|
17
17
|
k,v = arg.scan(is_param)[0]
|
18
18
|
else
|
19
|
-
|
19
|
+
@argv.push arg
|
20
20
|
end
|
21
21
|
if k and v
|
22
22
|
k = k.strip.to_sym
|
data/lib/args_parser/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'args_parser'
|
4
|
+
|
5
|
+
args = ArgsParser.parse ARGV, :style => :equal do
|
6
|
+
arg :help, 'show help', :alias => :h
|
7
|
+
|
8
|
+
on :help do |v|
|
9
|
+
STDERR.puts help
|
10
|
+
STDERR.puts "e.g. ruby equal_style.rb --user=shokai hello world --a=1234"
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
puts "== args"
|
16
|
+
p args
|
17
|
+
puts "== args.argv"
|
18
|
+
p args.argv
|
data/test/test_args_parser.rb
CHANGED
@@ -20,45 +20,45 @@ class TestArgsParser < MiniTest::Test
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_first
|
23
|
-
|
23
|
+
assert_equal @parser.first, 'test'
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_argv
|
27
|
-
|
27
|
+
assert_equal @parser.argv, ['test', 'foo', 'bar']
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_arg
|
31
|
-
|
31
|
+
assert_equal @parser[:input], 'http://shokai.org'
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_alias
|
35
|
-
|
35
|
+
assert_equal @parser[:output], './out'
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_string_access
|
39
|
-
|
39
|
+
assert_equal @parser['output'], './out'
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_cast_integer
|
43
|
-
|
44
|
-
|
43
|
+
assert_equal @parser[:depth], 30
|
44
|
+
assert_equal @parser[:depth].class, Fixnum
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_cast_float
|
48
|
-
|
49
|
-
|
48
|
+
assert_equal @parser[:pi], 3.14
|
49
|
+
assert_equal @parser[:pi].class, Float
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_filter
|
53
|
-
|
53
|
+
assert_equal @parser[:name], 'shokai'
|
54
54
|
end
|
55
55
|
|
56
56
|
def test_missing_arg
|
57
|
-
|
57
|
+
assert_equal @parser[:b], nil
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_switch
|
61
|
-
|
61
|
+
assert_equal @parser[:help], true
|
62
62
|
end
|
63
63
|
|
64
64
|
def test_has_param?
|
@@ -20,45 +20,45 @@ class TestArgsParserStyleEqual < MiniTest::Test
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_first
|
23
|
-
|
23
|
+
assert_equal @parser.first, 'test'
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_argv
|
27
|
-
|
27
|
+
assert_equal @parser.argv, ['test', 'foo', 'bar']
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_arg
|
31
|
-
|
31
|
+
assert_equal @parser[:input], 'http://shokai.org'
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_alias
|
35
|
-
|
35
|
+
assert_equal @parser[:output], './out'
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_string_access
|
39
|
-
|
39
|
+
assert_equal @parser['output'], './out'
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_cast_integer
|
43
|
-
|
44
|
-
|
43
|
+
assert_equal @parser[:depth], -30
|
44
|
+
assert_equal @parser[:depth].class, Fixnum
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_cast_float
|
48
|
-
|
49
|
-
|
48
|
+
assert_equal @parser[:pi], -3.14
|
49
|
+
assert_equal @parser[:pi].class, Float
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_filter
|
53
|
-
|
53
|
+
assert_equal @parser[:name], 'shokai'
|
54
54
|
end
|
55
55
|
|
56
56
|
def test_missing_arg
|
57
|
-
|
57
|
+
assert_equal @parser[:b], nil
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_switch
|
61
|
-
|
61
|
+
assert_equal @parser[:help], true
|
62
62
|
end
|
63
63
|
|
64
64
|
def test_has_param?
|
data/test/test_default.rb
CHANGED
@@ -11,11 +11,11 @@ class TestArgsParserDefault < MiniTest::Test
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_default
|
14
|
-
|
14
|
+
assert_equal @parser[:name], 'shokai'
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_overwrite
|
18
|
-
|
18
|
+
assert_equal @parser[:age], 40
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_name
|
data/test/test_helper.rb
CHANGED
data/test/test_on.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path 'test_helper', File.dirname(__FILE__)
|
2
|
+
|
3
|
+
class TestArgsParserOn < MiniTest::Test
|
4
|
+
|
5
|
+
def test_filter_error
|
6
|
+
argv = ['--h', '--say', 'hello']
|
7
|
+
help_called = false
|
8
|
+
say_called = false
|
9
|
+
args = ArgsParser.parse argv do
|
10
|
+
arg :help, 'show help', :alias => :h
|
11
|
+
arg :say, 'string'
|
12
|
+
|
13
|
+
on :say do |v|
|
14
|
+
say_called = v
|
15
|
+
end
|
16
|
+
|
17
|
+
on :help do
|
18
|
+
help_called = true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_equal say_called, "hello"
|
23
|
+
assert_equal help_called, true
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/test/test_validator.rb
CHANGED
@@ -12,7 +12,7 @@ class TestArgsParserValidator < MiniTest::Test
|
|
12
12
|
validate :url, 'invalid URL' do |v|
|
13
13
|
v =~ Regexp.new("^https?://.+$")
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
on_validate_error do |err, name, value|
|
17
17
|
@@err = err
|
18
18
|
@@name = name
|
@@ -22,8 +22,8 @@ class TestArgsParserValidator < MiniTest::Test
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_validate_error
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
assert_equal @@name, :url
|
26
|
+
assert_equal @@value, 'hptt://shokai.org'
|
27
|
+
assert_equal @@err.class, ArgsParser::ValidationError
|
28
28
|
end
|
29
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: args_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sho Hashimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -84,22 +84,25 @@ files:
|
|
84
84
|
- lib/args_parser/config.rb
|
85
85
|
- lib/args_parser/error.rb
|
86
86
|
- lib/args_parser/filter.rb
|
87
|
+
- lib/args_parser/main.rb
|
87
88
|
- lib/args_parser/parser.rb
|
88
89
|
- lib/args_parser/styles/default.rb
|
89
90
|
- lib/args_parser/styles/equal.rb
|
90
91
|
- lib/args_parser/validator.rb
|
91
92
|
- lib/args_parser/version.rb
|
92
93
|
- samples/download_webpage.rb
|
93
|
-
- samples/
|
94
|
+
- samples/equal_style.rb
|
94
95
|
- test/test_args_parser.rb
|
95
96
|
- test/test_args_parser_style_equal.rb
|
96
97
|
- test/test_default.rb
|
97
98
|
- test/test_filter.rb
|
98
99
|
- test/test_helper.rb
|
100
|
+
- test/test_on.rb
|
99
101
|
- test/test_validator.rb
|
100
102
|
- test/test_version.rb
|
101
103
|
homepage: http://shokai.github.com/args_parser
|
102
|
-
licenses:
|
104
|
+
licenses:
|
105
|
+
- MIT
|
103
106
|
metadata: {}
|
104
107
|
post_install_message:
|
105
108
|
rdoc_options: []
|
@@ -117,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
120
|
version: '0'
|
118
121
|
requirements: []
|
119
122
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.0.
|
123
|
+
rubygems_version: 2.0.5
|
121
124
|
signing_key:
|
122
125
|
specification_version: 4
|
123
126
|
summary: Parse/Filter/Validate ARGV from command line with DSL.
|
@@ -127,6 +130,6 @@ test_files:
|
|
127
130
|
- test/test_default.rb
|
128
131
|
- test/test_filter.rb
|
129
132
|
- test/test_helper.rb
|
133
|
+
- test/test_on.rb
|
130
134
|
- test/test_validator.rb
|
131
135
|
- test/test_version.rb
|
132
|
-
has_rdoc:
|
data/samples/twitter_timeline.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
## equal style sample app
|
3
|
-
## % gem install twitter --version=3.7.0
|
4
|
-
|
5
|
-
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
6
|
-
require 'rubygems'
|
7
|
-
require 'args_parser'
|
8
|
-
gem 'twitter', '< 4.0.0', '>= 3.7.0'
|
9
|
-
require 'twitter'
|
10
|
-
|
11
|
-
args = ArgsParser.parse ARGV, :style => :equal do
|
12
|
-
arg :user, 'user', :alias => :u
|
13
|
-
arg :favorite, 'show favorites', :alias => :fav
|
14
|
-
arg :retweet, 'show retweets', :alias => :rt
|
15
|
-
arg :help, 'show help', :alias => :h
|
16
|
-
|
17
|
-
filter :user do |v|
|
18
|
-
v.to_s.strip
|
19
|
-
end
|
20
|
-
|
21
|
-
validate :user, "invalid twitter screen_name" do |v|
|
22
|
-
v =~ /^[a-zA-Z0-9_]+$/
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
if args.has_option? :help or !args.has_param? :user
|
27
|
-
STDERR.puts "Twitter Timeline\n=="
|
28
|
-
STDERR.puts args.help
|
29
|
-
STDERR.puts "e.g. ruby #{$0} --user=ymrl"
|
30
|
-
STDERR.puts "e.g. ruby #{$0} --user=ymrl --fav"
|
31
|
-
STDERR.puts "e.g. ruby #{$0} --user=ymrl --fav --rt"
|
32
|
-
exit 1
|
33
|
-
end
|
34
|
-
|
35
|
-
p args
|
36
|
-
|
37
|
-
Twitter::configure do
|
38
|
-
end
|
39
|
-
|
40
|
-
data = []
|
41
|
-
Twitter::user_timeline(args[:user]).each do |i|
|
42
|
-
data.push(:id => i.id,
|
43
|
-
:name => i.user.screen_name,
|
44
|
-
:text => i.text,
|
45
|
-
:date => i.created_at)
|
46
|
-
end
|
47
|
-
|
48
|
-
if args.has_option? :favorite
|
49
|
-
Twitter::favorites(args[:user]).each do |i|
|
50
|
-
data.push(:id => i.id,
|
51
|
-
:name => i.user.screen_name,
|
52
|
-
:text => i.text,
|
53
|
-
:date => i.created_at)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
if args.has_option? :retweet
|
58
|
-
Twitter::retweeted_by_user(args[:user]).each do |i|
|
59
|
-
data.push(:id => i.id,
|
60
|
-
:name => i.user.screen_name,
|
61
|
-
:text => i.text,
|
62
|
-
:date => i.created_at)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
data.uniq{|i|
|
67
|
-
i[:id]
|
68
|
-
}.sort{|a,b|
|
69
|
-
a[:date] <=> b[:date]
|
70
|
-
}.each{|i|
|
71
|
-
puts "@#{i[:name]}\t#{i[:text]}"
|
72
|
-
}
|