lyne 0.0.2.5 → 0.0.2.6

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
  SHA1:
3
- metadata.gz: ea1d82a183033607f858c72013a2525cc4c8511f
4
- data.tar.gz: 7269371389a1217d40c60ce4cc97e3a550e5b695
3
+ metadata.gz: f873cc06ede289851018df24a5f9ad86f451ac55
4
+ data.tar.gz: 725e0496085d265e335c5a641addcc5dec9db7eb
5
5
  SHA512:
6
- metadata.gz: 04830c3f87a9369e6f3451b875980fd462a7d3f17b913bbc08dc431f66af85d98aa288175377dd56114779718d497008dabef145036f36cda1a5a87028626024
7
- data.tar.gz: 356c406dec1a188e0fd8ef63312f4112de4c32c0ad180268a24ff0f979cbb140b3b0fa56ae14b7604ec0d9479e9c089275d33e253679ad5d7d9dff54581aa748
6
+ metadata.gz: a5fd513d89731a80cb20ca98f9dce234cb2e2700e3fcac87436d4e1a3c1758ef6ba12c4e74d6be6f525568079999837493c06fcd4d01c0f9a62dfd13775d64db
7
+ data.tar.gz: 0eb76a15a2209c734c178ef030e0f4a5bb16929a0c4be4143716020321d75cff90d623cad87fe22c892ed7976ae35bc44beb55c1a20d4d2ac3360a2b8921cfba
data/README.md CHANGED
@@ -35,19 +35,58 @@ dqx = Lyne::Account.new(
35
35
  )
36
36
 
37
37
  chara = dqx.character
38
+ ```
39
+
40
+ ### Info Class
38
41
 
42
+ ```ruby
39
43
  info = chara.info
40
44
  info.id #=> "TV327-610"
41
45
  info.name #=> "ソプラナ"
42
46
  # フレンド申請おk
47
+ ```
48
+
49
+ ```
50
+ # id name job tribe level next_level gold genki_charge
43
51
 
52
+ > info.show_table
53
+
54
+ +---------+--------+--------------+------+------+--------------+----------+------------+
55
+ |ID |名前 |職業 |種族 |レベル|次のレベルまで|所持金 |元気チャージ|
56
+ +---------+--------+--------------+------+------+--------------+----------+------------+
57
+ |TV327-610|ソプラナ|バトルマスター|エルフ|80 | |2,340,609G|209時間 |
58
+ +---------+--------+--------------+------+------+--------------+----------+------------+
59
+ ```
60
+
61
+ ### House Class
62
+
63
+ ```ruby
44
64
  house = chara.house
45
- house.country #=> "アズラン住宅村"
46
- house.city #=> "おごそかな林道地区"
65
+ house.city #=> "アズラン住宅村"
66
+ house.area #=> "おごそかな林道地区"
47
67
  house.house_number #=> "3849丁目 6番地 (Sサイズ)"
48
68
  # 遊びにきておk
49
69
  ```
50
70
 
71
+ ```
72
+ # city area house_number setting setting_type
73
+
74
+ > house.show_table
75
+
76
+ +--------------+------------------+-------------------------+----------------------+------------------------+
77
+ |町 |地区 |番地 |ウェルカム設定 |設定内容 |
78
+ +--------------+------------------+-------------------------+----------------------+------------------------+
79
+ |アズラン住宅村|おごそかな林道地区|3849丁目6番地(Sサイズ)|ウェルカムハウス設定中|インテリアじまん・その他|
80
+ +--------------+------------------+-------------------------+----------------------+------------------------+
81
+ ```
82
+
83
+ ### キャラチェンジ
84
+
85
+ ```ruby
86
+ chara = dqx.character
87
+ chara.change('122233333444') #=> character_idを指定
88
+ ```
89
+
51
90
  # test
52
91
 
53
92
  ```bash
@@ -12,7 +12,7 @@ require './lib/lyne/session/browser.rb'
12
12
  require './lib/lyne/parser/base.rb'
13
13
  require './lib/lyne/parser/home.rb'
14
14
  require './lib/lyne/page/hook.rb'
15
- #require './lib/lyne/page/show_table.rb'
15
+ require './lib/lyne/page/show_table.rb'
16
16
  require './lib/lyne/page/character.rb'
17
17
 
18
18
  module Lyne
@@ -3,7 +3,7 @@ module Lyne::Page
3
3
  # Character情報に紐づくオブジェクト
4
4
  module Character
5
5
  class Base
6
- #include Lyne::Page::ShowTable
6
+ include Lyne::Page::ShowTable
7
7
 
8
8
  def initialize session
9
9
  @parser = parser_class.new(session)
@@ -24,7 +24,7 @@ module Lyne::Page
24
24
 
25
25
  private
26
26
  def table_headers
27
- %w(ID 名前 種族 職業 レベル 次のレベルまで 所持金 元気チャージ)
27
+ %w(ID 名前 職業 種族 レベル 次のレベルまで 所持金 元気チャージ)
28
28
  end
29
29
 
30
30
  def table_rows
@@ -38,10 +38,18 @@ module Lyne::Page
38
38
  end
39
39
 
40
40
  class House < Lyne::Page::Character::Base
41
- PROPERTYS = %w(country city house_number setting setting_type)
41
+ PROPERTYS = %w(city area house_number setting setting_type)
42
42
  include Lyne::Page::Hook::CreateProperty
43
43
 
44
44
  private
45
+ def table_headers
46
+ %w(町 地区 番地 ウェルカム設定 設定内容)
47
+ end
48
+
49
+ def table_rows
50
+ [city, area, house_number, setting, setting_type]
51
+ end
52
+
45
53
  def parser_class
46
54
  Lyne::Parser::House
47
55
  end
@@ -1,12 +1,73 @@
1
- #module Lyne::Page
2
- # module ShowTable
3
- # def show_table
4
- # table = Kosi::Table.new({header: table_headers})
5
- # print table.render([table_rows])
6
- # end
7
- #
8
- # private
9
- # def table_headers; [] end
10
- # def table_rows; [] end
11
- # end
12
- #end
1
+ class String
2
+ def byte_size
3
+ hankaku = self.scan(/[ -~。-゚]/).size
4
+ zenkaku = (self.size - hankaku)*2
5
+ hankaku + zenkaku
6
+ end
7
+ end
8
+
9
+ module Lyne::Util
10
+ class TerminalTable
11
+ def initialize header
12
+ @header = header
13
+ @table = []
14
+ end
15
+
16
+ def render rows
17
+ rows = rows.map{|r| r.nil? ? '' : r}
18
+ if @header.size > rows.size
19
+ rows = rows + Array.new(@header.size - rows.size, '')
20
+ else
21
+ @header = @header + Array.new(rows.size - @header.size, '')
22
+ end
23
+
24
+ table = width(@header.zip(rows))
25
+ width_list = table.map{|t|t[0]}
26
+ table_width = width_list.inject(&:+)
27
+ @width = "+#{width_list.map{|w| "#{'-'*w}+"}.join}"
28
+
29
+ puts_row
30
+
31
+ rows = [@header] + [rows]
32
+ rows.each_with_index do |row, i|
33
+ table_row = ''
34
+ row.each_with_index do |r, j|
35
+ blank_size = width_list[j] - r.byte_size
36
+ table_row += "#{r}#{" "*blank_size}|"
37
+ end
38
+ puts "|#{table_row}"
39
+ puts_row if i == 0
40
+ end
41
+ puts_row
42
+ end
43
+
44
+ private
45
+ def puts_header
46
+ puts "|#{@header.join(' ')}|"
47
+ puts "|#{@rows[0].join(' ')}|"
48
+ end
49
+
50
+ def puts_row
51
+ puts @width
52
+ end
53
+
54
+ def width table
55
+ table.inject([]) do |new_table, old_table|
56
+ new_table << old_table.unshift(old_table.map{|t| t.nil? ? 0 : t.byte_size}.max)
57
+ new_table
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ module Lyne::Page
64
+ module ShowTable
65
+ def show_table
66
+ Lyne::Util::TerminalTable.new(table_headers).render(table_rows)
67
+ end
68
+
69
+ private
70
+ def table_headers; [] end
71
+ def table_rows; [] end
72
+ end
73
+ end
@@ -21,12 +21,12 @@ module Lyne::Parser
21
21
  raise Lyne::Error::ParseError.new if parse_data.blank?
22
22
  option = option.reverse_merge(default_parse_result_options)
23
23
  text = parse_data.children[option[:index]].children.text
24
-
25
- if option[:regexp].present?
26
- text.gsub(option[:regexp], '')
27
- else
28
- text
29
- end
24
+ text = if option[:regexp].present?
25
+ text.gsub(option[:regexp], '')
26
+ else
27
+ text
28
+ end
29
+ text.gsub(/\s|#{nbsp}/,'')
30
30
  end
31
31
 
32
32
  def default_parse_result_options
@@ -55,19 +55,27 @@ module Lyne::Parser
55
55
  end
56
56
 
57
57
  class House < Home
58
- def country
58
+ def city
59
59
  text = get_parse_data(index: 3)
60
60
  text.split[0].scan(/.*住宅村/)[0] if text.present?
61
61
  end
62
62
 
63
- def city
63
+ def area
64
64
  text = get_parse_data(index: 3)
65
- text.split[0].gsub(/#{country}/,'') if text.present?
65
+ if text.present? && text =~ /\d/
66
+ text[0...text.index(/\d/)].gsub(/#{city}/,'')
67
+ else
68
+ nil
69
+ end
66
70
  end
67
71
 
68
72
  def house_number
69
73
  text = get_parse_data(index: 3)
70
- text.split[1] if text.present?
74
+ if text.present? && text =~ /\d/
75
+ text[text.index(/\d/)..-1]
76
+ else
77
+ nil
78
+ end
71
79
  end
72
80
 
73
81
  def setting
@@ -1,3 +1,3 @@
1
1
  module Lyne
2
- VERSION = "0.0.2.5"
2
+ VERSION = "0.0.2.6"
3
3
  end
@@ -38,8 +38,8 @@ describe Lyne::Page::Character do
38
38
  context 'Houseが取得できているる' do
39
39
  subject{ @character.house }
40
40
 
41
- context 'countryが取得できている' do
42
- it { expect(subject.country).to match(/.*住宅村$/) }
41
+ context 'cityが取得できている' do
42
+ it { expect(subject.city).to match(/.*住宅村$/) }
43
43
  end
44
44
 
45
45
  context 'house_numberが取得できている' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lyne
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.5
4
+ version: 0.0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - soplana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-07 00:00:00.000000000 Z
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler