itaiji 0.2.0 → 0.3.0

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.
@@ -0,0 +1,39 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ module Itaiji
5
+ class Fetcher
6
+ URL = "https://wwwap.hi.u-tokyo.ac.jp/ships/itaiji_list.jsp"
7
+
8
+ def fetch
9
+ doc = Nokogiri::HTML(open(URL))
10
+
11
+ itaiji_sets = doc.xpath("//tr[contains(@class, 'g') or contains(@class, 'w')]").map do |element|
12
+ _, seijitai_element, itaiji_element = element.xpath(".//td")
13
+ itaijis = itaiji_element.text.split(" ")
14
+ Set.new(seijitai_element.text.strip, itaijis.take(itaijis.length - 1))
15
+ end
16
+
17
+ List.new(itaiji_sets)
18
+ end
19
+ end
20
+
21
+ class Set
22
+ attr_reader :seijitai, :itaijis
23
+
24
+ def initialize(seijitai, itaijis)
25
+ @seijitai = seijitai
26
+ @itaijis = itaijis
27
+ end
28
+ end
29
+
30
+ class List
31
+ def initialize(itaiji_sets)
32
+ @itaiji_sets = itaiji_sets
33
+ end
34
+
35
+ def to_h
36
+ @itaiji_sets
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Itaiji
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/itaiji.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'yaml'
1
2
  require 'itaiji/version'
2
3
  require 'itaiji/converter'
3
4
  require 'itaiji/core_ext/string/conversions'