ttsttb 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c64ead79b53e522b03905ca4201eb0ca0aae343dbe1b651403bc59c5eae83faf
4
- data.tar.gz: '03760922b03c8179709651a8a0fe8e8f30c9c6907a9993550f217923bc050cbb'
3
+ metadata.gz: ea73f2ec6452e43f2b4f950395f6c5cb676f51e7823654e7a19875941b40b09f
4
+ data.tar.gz: e5750051b807160c297b4194842355f4ccfe557caac8644d94cdb6334767b76e
5
5
  SHA512:
6
- metadata.gz: cced5dc5b6220ea62e8f161ff49ae513cb0a78c40411dc76305db86a3f49f69ef921f8899095492a1ddba141f1cdac71aaffd652ed67602274e3efa7675b0cb1
7
- data.tar.gz: 36567e5174a43ea6878cfe1792eea0fdd9cfdcbeaddf231109fc04b49e2fddc5744891bca2197fc505fc591dd45f8d36852716ce291d88bc987b945fa1ef947b
6
+ metadata.gz: b0523bc57febfc43c0affa1f6b69f60caaf3498bf90b52e1f3aefdbf6efd1a0efca37bc314e48eea369e5e2db3c14af2408338f5c617f73b027033dc594c3315
7
+ data.tar.gz: 7b443570cb3d3bdc79492d4017fba9d83b9b5fe3b041679702ed8d945da88ee80a6f1b610a16a640d59c151f9d79286f54c065340ce9063870bc53e091792e6c
@@ -0,0 +1,22 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-02-23 11:31:57 +0900 using RuboCop version 0.48.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Metrics/AbcSize:
11
+ Max: 26
12
+
13
+ # Offense count: 1
14
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
15
+ # URISchemes: http, https
16
+ Metrics/LineLength:
17
+ Max: 99
18
+
19
+ # Offense count: 1
20
+ # Configuration parameters: CountComments.
21
+ Metrics/MethodLength:
22
+ Max: 16
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ttsttb (0.0.1)
4
+ ttsttb (0.0.3)
5
5
  nokogiri
6
6
 
7
7
  GEM
@@ -1,16 +1,28 @@
1
1
  require 'ttsttb/version'
2
+ require 'nokogiri'
2
3
 
4
+ # Scrape TTS and TTB data from MURC.
3
5
  module Ttsttb
6
+ # Execute scraping
4
7
  def self.find(date)
5
- require 'date'
6
- url = 'http://www.murc-kawasesouba.jp/fx/past/index.php?id=%s' % [date.strftime('%y%m%d')]
8
+ # TODO
9
+ throw 'Data of today is not supported yet.' if date == Date.today
7
10
 
8
- rows = {}
11
+ # TODO
12
+ throw 'Old data is not supported yet.' if date == Date.new(2006, 1, 1)
13
+
14
+ require 'date'
15
+ url = format('http://www.murc-kawasesouba.jp/fx/past/index.php?id=%s', date.strftime('%y%m%d'))
9
16
 
10
17
  require 'open-uri'
11
- require 'nokogiri'
12
18
 
13
19
  doc = Nokogiri::HTML(open(url, redirect: false))
20
+ scrape(doc)
21
+ end
22
+
23
+ # parse document
24
+ def self.scrape(doc)
25
+ rows = {}
14
26
  doc.xpath('//table[1]/tr').each do |tr|
15
27
  tds = tr.xpath('.//td')
16
28
 
@@ -22,11 +34,28 @@ module Ttsttb
22
34
  'ja' => tds[1].content
23
35
  },
24
36
  'code' => tds[2].content,
25
- 'tts' => tds[3].content.strip.to_f,
26
- 'ttb' => tds[4].content.strip.to_f
37
+ 'tts' => normalize(tds[3].content),
38
+ 'ttb' => normalize(tds[4].content),
39
+ 'ttm' => get_ttm(normalize(tds[3].content), normalize(tds[4].content))
27
40
  }
28
41
  end
29
42
 
30
43
  rows
31
44
  end
45
+
46
+ # normalize string to float
47
+ def self.normalize(value)
48
+ value = value.strip
49
+ return nil if value == 'unquoted'
50
+ value.to_f
51
+ end
52
+
53
+ # calculate TTM
54
+ def self.get_ttm(tts, ttb)
55
+ require 'bigdecimal'
56
+
57
+ return nil unless tts && ttb
58
+
59
+ (BigDecimal(tts.to_s) + BigDecimal(ttb.to_s) / 2).round(2).to_f
60
+ end
32
61
  end
@@ -1,3 +1,3 @@
1
1
  module Ttsttb
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttsttb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Matsukura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-22 00:00:00.000000000 Z
11
+ date: 2018-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
+ - ".rubocop.yml"
63
64
  - Gemfile
64
65
  - Gemfile.lock
65
66
  - README.md