ruboty-fop 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +48 -0
- data/LICENSE.txt +21 -0
- data/README.md +114 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ruboty/fop.rb +2 -0
- data/lib/ruboty/handlers/fop.rb +256 -0
- data/lib/ruboty-fop/version.rb +3 -0
- data/ruboty-fop.gemspec +27 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b408edfc947e91da2648c7c24d3aef8fcdd050f56ebcb01e2b367c813efc77d8
|
4
|
+
data.tar.gz: 0a77cc6379b6c0e4a6a415cbb340f3dc7a9061972b684ec2dbcd9d4d4dde1c1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3ff9c5f8ab37f866cf7e61d65a62304ab07556806e5fa7c31b56a70c92dd4ee5e8bef2839fdaa6aa2c6eb1500d1bbca462e9bde52ec1105835a29b82b0765ae
|
7
|
+
data.tar.gz: d03a4a7373ddb4fe3b958f6ced3e244897b4055b08c1dc1e411c29d54983e3c104b22dac14fee76d609b4b6033909afd7a6c0ede03b21626e1d91cdf85b35c07
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruboty-fop (0.0.1)
|
5
|
+
fop
|
6
|
+
ruboty
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (5.1.4)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (~> 0.7)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
concurrent-ruby (1.0.5)
|
17
|
+
dotenv (2.2.1)
|
18
|
+
fop (0.1.0)
|
19
|
+
nokogiri
|
20
|
+
i18n (0.9.1)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
mem (0.1.5)
|
23
|
+
mini_portile2 (2.3.0)
|
24
|
+
minitest (5.10.3)
|
25
|
+
nokogiri (1.8.1)
|
26
|
+
mini_portile2 (~> 2.3.0)
|
27
|
+
rake (12.3.0)
|
28
|
+
ruboty (1.3.0)
|
29
|
+
activesupport
|
30
|
+
bundler
|
31
|
+
dotenv
|
32
|
+
mem
|
33
|
+
slop
|
34
|
+
slop (4.6.1)
|
35
|
+
thread_safe (0.3.6)
|
36
|
+
tzinfo (1.2.4)
|
37
|
+
thread_safe (~> 0.1)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
bundler
|
44
|
+
rake
|
45
|
+
ruboty-fop!
|
46
|
+
|
47
|
+
BUNDLED WITH
|
48
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Sorah Fukumori
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# Ruboty::Fop: Ruboty handler for JAL Mileage/FOP calculator
|
2
|
+
|
3
|
+
- https://github.com/sorah/fop
|
4
|
+
- https://github.com/sorah/ruboty-fop
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'ruboty-fop'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install ruboty-fop
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```
|
25
|
+
Usage:
|
26
|
+
ruboty fop help
|
27
|
+
ruboty fop list {dom|intl} airports [filter]
|
28
|
+
ruboty fop dom FROM-TO [-class CLASS] [-fare FARE] [-card CARD] [-status STATUS]
|
29
|
+
ruboty fop intl FROM-TO [-fare FARE] [-card CARD] [-status STATUS]
|
30
|
+
ruboty fop prefer [-class CLASS] [-fare-dom FARE] [-fare-intl FARE] [-card CARD] [-status STATUS]
|
31
|
+
|
32
|
+
Example:
|
33
|
+
ruboty fop prefer -card global -status sapphire
|
34
|
+
ruboty fop dom TYO-OKA -class J -fare discount
|
35
|
+
```
|
36
|
+
|
37
|
+
```
|
38
|
+
> ruboty fop list 東京
|
39
|
+
- dom: `TYO` 東京(羽田・成田)
|
40
|
+
- intl: `TYO` 東京
|
41
|
+
|
42
|
+
> ruboty fop hnd-itm
|
43
|
+
fare is required
|
44
|
+
- `normal` 運賃1(100%): 大人普通運賃、小児普通運賃、往復割引、身体障がい者割引、介護帰省割引、JALビジネスきっぷ、eビジネス6、シャトル往復割引、離島割引、国際線航空券に含まれる日本国内区間*1など
|
45
|
+
- `fare2` 運賃2(100%): 特別乗継割引
|
46
|
+
- `discount` 運賃3(75%): 先得割引、スーパー先得、ウルトラ先得、乗継割引28
|
47
|
+
- `discountOther` 運賃4(75%): 特便割引1、特便割引3、特便割引7、特便割引21、特別往復割引、株主割引
|
48
|
+
- `fare5` 運賃5(75%): 乗継割引7
|
49
|
+
- `fare6` 運賃6(75%): 当日シルバー割引、おともdeマイル割引*2、スカイメイト
|
50
|
+
- `inclusive` 運賃7(50%): パッケージツアーに適用される個人包括旅行運賃など
|
51
|
+
|
52
|
+
> ruboty fop hnd-itm -fare discount -class J
|
53
|
+
TYO (東京(羽田・成田)) - OSA (大阪(伊丹・関西))
|
54
|
+
クラス J, 運賃3(75%), - (JALカードCLUB-A会員)
|
55
|
+
|
56
|
+
*single-trip 298 miles, 476 FOP*
|
57
|
+
*round-trip 596 miles, 952 FOP*
|
58
|
+
|
59
|
+
Mileage:
|
60
|
+
- 238 ( フライトマイル 区間マイルの85% (区間マイルの75% + クラス J 分) )
|
61
|
+
- 60 ( ボーナスマイル フライトマイルの25%JALカードCLUB-A会員 )
|
62
|
+
FOP:
|
63
|
+
- 238 * 2.0
|
64
|
+
|
65
|
+
|
66
|
+
> ruboty fop hnd-sfo -fare first -card global -status sapphire
|
67
|
+
TYO (東京) - SFO (サンフランシスコ)
|
68
|
+
ファーストクラス運賃(150%), JMBサファイア (JALグローバルクラブ会員(日本地区))
|
69
|
+
|
70
|
+
*single-trip 15775 miles, 8095 FOP*
|
71
|
+
*round-trip 31550 miles, 16190 FOP*
|
72
|
+
|
73
|
+
Mileage:
|
74
|
+
- 7695 ( フライトマイル 区間マイルの150% )
|
75
|
+
- 8080 ( ボーナスマイル フライトマイルの105%JMBサファイア会員/JALカード会員 )
|
76
|
+
FOP:
|
77
|
+
- 7695 * 1.0
|
78
|
+
- 400 ( キャンペーンボーナスポイントファーストクラス運賃 )
|
79
|
+
|
80
|
+
|
81
|
+
> ruboty fop prefer -intl-fare first -card global -status sapphire
|
82
|
+
preference updated:
|
83
|
+
{:"intl-fare"=>"first", :card=>"global", :status=>"sapphire"}
|
84
|
+
|
85
|
+
|
86
|
+
> ruboty fop hnd-syd
|
87
|
+
TYO (東京) - SYD (シドニー)
|
88
|
+
ファーストクラス運賃(150%), JMBサファイア (JALグローバルクラブ会員(日本地区))
|
89
|
+
|
90
|
+
*single-trip 14955 miles, 11342 FOP*
|
91
|
+
*round-trip 29910 miles, 22684 FOP*
|
92
|
+
|
93
|
+
Mileage:
|
94
|
+
- 7295 ( フライトマイル 区間マイルの150% )
|
95
|
+
- 7660 ( ボーナスマイル フライトマイルの105%JMBサファイア会員/JALカード会員 )
|
96
|
+
FOP:
|
97
|
+
- 7295 * 1.5
|
98
|
+
- 400 ( キャンペーンボーナスポイントファーストクラス運賃 )
|
99
|
+
```
|
100
|
+
|
101
|
+
|
102
|
+
## Development
|
103
|
+
|
104
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
105
|
+
|
106
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
107
|
+
|
108
|
+
## Contributing
|
109
|
+
|
110
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sorah/ruboty-fop.
|
111
|
+
|
112
|
+
## License
|
113
|
+
|
114
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruboty/fop"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/ruboty/fop.rb
ADDED
@@ -0,0 +1,256 @@
|
|
1
|
+
require "ruboty-fop/version"
|
2
|
+
require 'ruboty/handlers/base'
|
3
|
+
require 'fop'
|
4
|
+
|
5
|
+
module Ruboty
|
6
|
+
module Handlers
|
7
|
+
class Fop < Base
|
8
|
+
VERSION = RubotyFop::VERSION
|
9
|
+
|
10
|
+
USEFUL_AIRPORT_ALIASES = {
|
11
|
+
'HND' => 'TYO',
|
12
|
+
'NRT' => 'TYO',
|
13
|
+
'ITM' => 'OSA',
|
14
|
+
'KIX' => 'OSA',
|
15
|
+
}
|
16
|
+
|
17
|
+
on(/imascg(?:\s+?(?<mode>.+?))?(?:\s+?me)?\s+(?<query>.+)$/, name: 'imascg', description: 'find imascg cards')
|
18
|
+
on(/imascg flush cache/, name: 'imascg_flush', description: 'flush imascg query cache')
|
19
|
+
|
20
|
+
on(/fop\s+help$/, name: 'fop_help', description: 'JAL calculator help')
|
21
|
+
on(/fop\s+list(?:(?:\s+airports?)?(?:\s+(?<filter>.+))?)?$/, name: 'fop_airports', description: 'JAL calculator: List airports')
|
22
|
+
on(/fop\s+(?:I\s+)?prefer(?<options>(?:\s+-(?:class|(?:dom|intl)-fare|card|status)\s+[^\s]+)*)\s*$/i, name: 'fop_prefer', description: 'JAL calculator: Set preference')
|
23
|
+
on(/fop\s+(?<from>[a-zA-Z0-9]+?)[\/-](?<to>[a-zA-Z0-9]+?)\s*(?<options>(?:\s+-(?:class|fare|card|status)\s+[^\s]+)*)\s*$/, name: 'fop_calc', description: 'JAL calculator')
|
24
|
+
|
25
|
+
def fop_help(message)
|
26
|
+
message.reply <<-EOF
|
27
|
+
Usage:
|
28
|
+
ruboty fop help
|
29
|
+
ruboty fop list {dom|intl} airports [filter]
|
30
|
+
ruboty fop dom FROM-TO [-class CLASS] [-fare FARE] [-card CARD] [-status STATUS]
|
31
|
+
ruboty fop intl FROM-TO [-fare FARE] [-card CARD] [-status STATUS]
|
32
|
+
ruboty fop prefer [-class CLASS] [-fare-dom FARE] [-fare-intl FARE] [-card CARD] [-status STATUS]
|
33
|
+
|
34
|
+
Example:
|
35
|
+
ruboty fop prefer -card global -status sapphire
|
36
|
+
ruboty fop dom TYO-OKA -class J -fare discount
|
37
|
+
|
38
|
+
STATUS: #{fop.valid_statuses.map { |_| "`#{_.code}` #{_.name}" }.join(", ")}
|
39
|
+
CARD:
|
40
|
+
#{fop.valid_cards.map { |_| "- `#{_.code}` #{_.name}" }.join("\n")}
|
41
|
+
|
42
|
+
CLASS: #{fop.valid_dom_classes.map { |_| "`#{_.code}` #{_.name}" }.join(", ")}
|
43
|
+
FARE:
|
44
|
+
#{fop.valid_dom_fares.map { |_| "- dom: `#{_.code}` #{_.name}: #{_.remark}" }.join("\n")}
|
45
|
+
#{fop.valid_intl_fares.map { |_| "- intl: `#{_.code}` #{_.name}: #{_.remark}" }.join("\n")}
|
46
|
+
EOF
|
47
|
+
rescue ::Fop::Error
|
48
|
+
message.reply e.inspect
|
49
|
+
rescue StandardError => e
|
50
|
+
message.reply e.inspect
|
51
|
+
end
|
52
|
+
|
53
|
+
def fop_airports(message)
|
54
|
+
filter = message[:filter]
|
55
|
+
filter = nil if filter.nil? || filter.strip.empty?
|
56
|
+
filter = filter&.upcase
|
57
|
+
|
58
|
+
if filter
|
59
|
+
airports = (fop.valid_dom_airports + fop.valid_intl_airports_for_earning).select { |_| filter.nil? || _.code.include?(filter) || _.name.include?(filter) }
|
60
|
+
message.reply airports.map{ |_| "- #{_.area ? 'intl' : 'dom'}: `#{_.code}` #{_.name}" }[0,15].join("\n")
|
61
|
+
else
|
62
|
+
message.reply "dom: #{fop.valid_dom_airports.map(&:code).join(", ")}\nintl: #{fop.valid_intl_airports_for_earning.map(&:code).join(", ")}"
|
63
|
+
end
|
64
|
+
rescue ::Fop::Error
|
65
|
+
message.reply e.inspect
|
66
|
+
rescue StandardError => e
|
67
|
+
message.reply e.inspect
|
68
|
+
end
|
69
|
+
|
70
|
+
def fop_calc(message)
|
71
|
+
from_name = USEFUL_AIRPORT_ALIASES[message[:from].upcase] || message[:from].upcase
|
72
|
+
to_name = USEFUL_AIRPORT_ALIASES[message[:to].upcase] || message[:to].upcase
|
73
|
+
|
74
|
+
intl_from = fop.valid_intl_airports_for_earning.find { |_| _.code == from_name }
|
75
|
+
intl_to = fop.valid_intl_airports_for_earning.find { |_| _.code == to_name }
|
76
|
+
dom_from = fop.valid_dom_airports.find { |_| _.code == from_name }
|
77
|
+
dom_to = fop.valid_dom_airports.find { |_| _.code == to_name }
|
78
|
+
|
79
|
+
raise ::Fop::Error, "airport #{from_name} is not valid" unless intl_from || dom_from
|
80
|
+
raise ::Fop::Error, "airport #{to_name} is not valid" unless intl_to || dom_to
|
81
|
+
|
82
|
+
is_intl = (intl_from && intl_to) && (dom_from.nil? || dom_to.nil?)
|
83
|
+
if is_intl
|
84
|
+
from, to = intl_from, intl_to
|
85
|
+
else
|
86
|
+
from, to = dom_from, dom_to
|
87
|
+
end
|
88
|
+
|
89
|
+
options = {
|
90
|
+
status: '0',
|
91
|
+
card: 'club-a',
|
92
|
+
}
|
93
|
+
parsed_options = parse_options(message[:options])
|
94
|
+
if is_intl
|
95
|
+
options.merge!(user_preference(message))
|
96
|
+
options[:fare] = options.delete(:'intl-fare')
|
97
|
+
options.merge!(parsed_options)
|
98
|
+
fare = find_intl_fare(options[:fare])
|
99
|
+
else
|
100
|
+
options.merge!(class: 'J')
|
101
|
+
options.merge!(user_preference(message))
|
102
|
+
options[:fare] = options.delete(:'dom-fare')
|
103
|
+
options.merge!(parsed_options)
|
104
|
+
klass = find_dom_class(options[:class])
|
105
|
+
fare = find_dom_fare(options[:fare])
|
106
|
+
end
|
107
|
+
|
108
|
+
card = find_card(options[:card])
|
109
|
+
status = find_status(options[:status])
|
110
|
+
|
111
|
+
if is_intl
|
112
|
+
result = fop.intl_search(
|
113
|
+
from: from,
|
114
|
+
to: to,
|
115
|
+
fare: fare,
|
116
|
+
card: card,
|
117
|
+
status: status,
|
118
|
+
)
|
119
|
+
else
|
120
|
+
result = fop.dom_search(
|
121
|
+
from: from,
|
122
|
+
to: to,
|
123
|
+
class: klass,
|
124
|
+
fare: fare,
|
125
|
+
card: card,
|
126
|
+
status: status,
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
message.reply <<-EOF
|
131
|
+
#{from.code} (#{from.name}) - #{to.code} (#{to.name})
|
132
|
+
#{klass ? "#{klass.name}, " : nil}#{fare.name}, #{status.name} (#{card.name})
|
133
|
+
|
134
|
+
*single-trip #{result.miles} miles, #{result.fop} FOP*
|
135
|
+
*round-trip #{result.miles * 2} miles, #{result.fop * 2} FOP*
|
136
|
+
|
137
|
+
Mileage:
|
138
|
+
- #{result.flight_miles} (#{result.flight_miles_remark})
|
139
|
+
#{result.bonus_miles ? "- #{result.bonus_miles} (#{result.bonus_miles_remark})" : nil}
|
140
|
+
FOP:
|
141
|
+
- #{result.flight_miles} * #{result.fop_rate}
|
142
|
+
#{result.fop_bonus ? "- #{result.fop_bonus } (#{result.fop_bonus_remark})" : nil}
|
143
|
+
EOF
|
144
|
+
rescue ::Fop::Error => e
|
145
|
+
message.reply e.message
|
146
|
+
rescue StandardError => e
|
147
|
+
message.reply e.inspect
|
148
|
+
end
|
149
|
+
|
150
|
+
def fop_prefer(message)
|
151
|
+
options = parse_options(message[:options])
|
152
|
+
preference = user_preference(message)
|
153
|
+
if options.empty?
|
154
|
+
message.reply "Your preference is:\n#{preference.inspect}"
|
155
|
+
else
|
156
|
+
options.each do |k, v|
|
157
|
+
case k
|
158
|
+
when :class; find_class(v)
|
159
|
+
when :'dom-fare'; find_dom_fare(v)
|
160
|
+
when :'intl-fare'; find_intl_fare(v)
|
161
|
+
when :card; find_card(v)
|
162
|
+
when :status; find_status(v)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
preference.merge!(options)
|
167
|
+
message.reply "preference updated:\n#{preference.inspect}"
|
168
|
+
end
|
169
|
+
rescue ::Fop::Error => e
|
170
|
+
message.reply e.message
|
171
|
+
rescue StandardError => e
|
172
|
+
message.reply e.inspect
|
173
|
+
end
|
174
|
+
|
175
|
+
private
|
176
|
+
|
177
|
+
def fop
|
178
|
+
@fop ||= ::Fop::Client.new
|
179
|
+
end
|
180
|
+
|
181
|
+
def find_dom_class(str)
|
182
|
+
klass = fop.valid_dom_classes.find { |_| _.code == str }
|
183
|
+
unless klass
|
184
|
+
list = fop.valid_dom_classes.map { |_| "- `#{_.code}` #{_.name}" }.join("\n")
|
185
|
+
if str
|
186
|
+
raise ::Fop::Error, "class #{str.inspect} is not valid\n#{list}"
|
187
|
+
else
|
188
|
+
raise ::Fop::Error, "class is required\n#{list}"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
klass
|
192
|
+
end
|
193
|
+
|
194
|
+
def find_dom_fare(str)
|
195
|
+
fare = fop.valid_dom_fares.find { |_| _.code == str }
|
196
|
+
unless fare
|
197
|
+
list = fop.valid_dom_fares.map { |_| "- `#{_.code}` #{_.name}: #{_.remark}" }.join("\n")
|
198
|
+
if str
|
199
|
+
raise ::Fop::Error, "fare #{str.inspect} is not valid\n#{list}"
|
200
|
+
else
|
201
|
+
raise ::Fop::Error, "fare is required\n#{list}"
|
202
|
+
end
|
203
|
+
end
|
204
|
+
fare
|
205
|
+
end
|
206
|
+
|
207
|
+
def find_intl_fare(str)
|
208
|
+
fare = fop.valid_intl_fares.find { |_| _.code == str }
|
209
|
+
unless fare
|
210
|
+
list = fop.valid_intl_fares.map { |_| "- `#{_.code}` #{_.name}: #{_.remark}" }.join("\n")
|
211
|
+
if str
|
212
|
+
raise ::Fop::Error, "fare #{str.inspect} is not valid\n#{list}"
|
213
|
+
else
|
214
|
+
raise ::Fop::Error, "fare is required\n#{list}"
|
215
|
+
end
|
216
|
+
end
|
217
|
+
fare
|
218
|
+
end
|
219
|
+
|
220
|
+
def find_card(str)
|
221
|
+
card = fop.valid_cards.find { |_| _.code == str }
|
222
|
+
unless card
|
223
|
+
list = fop.valid_cards.map { |_| "- `#{_.code}` #{_.name}" }.join("\n")
|
224
|
+
if str
|
225
|
+
raise ::Fop::Error, "card #{str.inspect} is not valid\n#{list}"
|
226
|
+
else
|
227
|
+
raise ::Fop::Error, "card is required\n#{list}"
|
228
|
+
end
|
229
|
+
end
|
230
|
+
card
|
231
|
+
end
|
232
|
+
|
233
|
+
def find_status(str)
|
234
|
+
status = fop.valid_statuses.find { |_| _.code == str }
|
235
|
+
unless status
|
236
|
+
list = fop.valid_statuses.map { |_| "- `#{_.code}` #{_.name}" }.join("\n")
|
237
|
+
if str
|
238
|
+
raise ::Fop::Error, "status #{str.inspect} is not valid\n#{list}"
|
239
|
+
else
|
240
|
+
raise ::Fop::Error, "status is required\n#{list}"
|
241
|
+
end
|
242
|
+
end
|
243
|
+
status
|
244
|
+
end
|
245
|
+
|
246
|
+
def user_preference(message)
|
247
|
+
u = message.original.dig(:user, 'id') || message.from_name
|
248
|
+
(robot.brain.data['fop.preference'] ||= {})[u] ||= {}
|
249
|
+
end
|
250
|
+
|
251
|
+
def parse_options(str)
|
252
|
+
str&.scan(/-(.+?) (.+?)(?:\s+|$)/)&.map{ |_| [_[0].to_sym, _[1]] }.to_h || {}
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
data/ruboty-fop.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "ruboty-fop/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ruboty-fop"
|
7
|
+
spec.version = RubotyFop::VERSION
|
8
|
+
spec.authors = ["Sorah Fukumori"]
|
9
|
+
spec.email = ["her@sorah.jp"]
|
10
|
+
|
11
|
+
spec.summary = %q{Japan Airlines FOP/Mileage calculation via Ruboty}
|
12
|
+
spec.homepage = "https://github.com/sorah/ruboty-fop"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "ruboty"
|
23
|
+
spec.add_dependency "fop"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-fop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sorah Fukumori
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruboty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- her@sorah.jp
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- lib/ruboty-fop/version.rb
|
85
|
+
- lib/ruboty/fop.rb
|
86
|
+
- lib/ruboty/handlers/fop.rb
|
87
|
+
- ruboty-fop.gemspec
|
88
|
+
homepage: https://github.com/sorah/ruboty-fop
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.7.3
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Japan Airlines FOP/Mileage calculation via Ruboty
|
112
|
+
test_files: []
|