ehbrs_ruby_utils 0.25.1 → 0.26.0

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: 3c7b8c03f444eeecd6bc0cf3294b7fdb87d853e794d882a33075fc144d6e0643
4
- data.tar.gz: 6d9ea47d713deb5f42930df49bf59beaa5d7feeadcaf1f317c2f72265e5645ac
3
+ metadata.gz: '01492301e8c9f767213720ca3b78b900225fdb359f6f140ca7b29598af9ce125'
4
+ data.tar.gz: e6ac5d5ee6b8f2d5e667df6a0eb196283d21be8da3e42636d80fbedfa1be5aec
5
5
  SHA512:
6
- metadata.gz: 337fc2b2871c7546da3c36e7362463541466f77f94a32ac7813c68692dce1c0e0883d6dd765bbc1b0226a502ed0a9049f6b49debbf920f68d370e2b478ead4b5
7
- data.tar.gz: db9aefd67166403008410368a68b5bde75777b3d819b7e0c829fb0b83a687af08f7b3e320ce2d840a0cfd38abaca8fbdf036adc785c3de4fbe8ae9451e5a4241
6
+ metadata.gz: 3a47e3110e4640dc017c1265b9bfd0f36661fe3e38379cdcdca9fd7bee8cb40acc6cb1385501f7f57f44a71a7ac0831725c51d4a977b0b7e5c2547298a9e8aeb
7
+ data.tar.gz: 2354c44fe899307ffba53b2be8843cb542f2095a0dd03efccc566a01fdc0641a699a30d190556febe6e0a7177134c3e94323a2a6a7f90d1c2072e34a68c6f354
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'aranha/parsers/html/item'
4
4
  require 'aranha/parsers/html/item_list'
5
+ require 'dentaku'
5
6
  require 'eac_ruby_utils/core_ext'
6
7
 
7
8
  module EhbrsRubyUtils
@@ -10,17 +11,41 @@ module EhbrsRubyUtils
10
11
  class Table < ::Aranha::Parsers::Html::Item
11
12
  class Players < ::Aranha::Parsers::Html::ItemList
12
13
  ITEMS_XPATH = '//div[starts-with(@id, "score_entry_")]'
14
+ RANK_VALUES = { vencedor: 1, perdedor: 2 }.freeze
13
15
 
14
- field :table_rank, :integer, './div[@class = "rank"]'
16
+ field :rank, :string, './div[@class = "rank"]'
15
17
  field :id, :integer, './div[@class = "name"]/a/@href'
16
18
  field :name, :string, './div[@class = "name"]/a/text()'
17
19
  field :score, :integer_optional, './div[@class = "score"]'
18
- field :win_points, :string, './/*[starts-with(@id, "winpoints_value_")]/text()'
19
- field :game_rank, :integer, './/*[@class = "gamerank_value"]/text()'
20
+ field :elo_increment, :string, './/*[starts-with(@id, "winpoints_value_")]/text()'
21
+ field :elo_reached, :integer, './/*[@class = "gamerank_value"]/text()'
22
+ field :penalty_clock, :boolean,
23
+ './/*[@class = "clockpenalty" and @style = "display: inline;"]'
24
+ field :penalty_leave, :boolean,
25
+ './/*[@class = "leavepenalty" and @style = "display: inline;"]'
20
26
 
21
27
  def items_xpath
22
28
  ITEMS_XPATH
23
29
  end
30
+
31
+ def item_data(data)
32
+ %i[elo_increment rank].inject(data) do |a, e|
33
+ a.merge(e => send("process_#{e}", data.fetch(e)))
34
+ end
35
+ end
36
+
37
+ # @return [Integer, nil]
38
+ def process_elo_increment(expression)
39
+ return nil if expression.blank?
40
+
41
+ ::Dentaku::Calculator.new.evaluate(expression.gsub(/\A\+/, '')).to_i
42
+ end
43
+
44
+ # @param value [String]
45
+ # @return [Integer]
46
+ def process_rank(source)
47
+ RANK_VALUES[source.downcase.to_sym] || source.to_i
48
+ end
24
49
  end
25
50
  end
26
51
  end
@@ -16,7 +16,7 @@ module EhbrsRubyUtils
16
16
  end
17
17
 
18
18
  def table_rank
19
- "*#{player.table_rank}º*"
19
+ "*#{player.rank}º*"
20
20
  end
21
21
 
22
22
  delegate :name, to: :player
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.25.1'
4
+ VERSION = '0.26.0'
5
5
  end
@@ -20,16 +20,20 @@
20
20
  :value: Desligado
21
21
  :description: ''
22
22
  :players:
23
- - :table_rank: 1
23
+ - :rank: 1
24
24
  :id: 84920871
25
25
  :name: eduardobogoni
26
26
  :score: 53
27
- :win_points: ''
28
- :game_rank:
29
- - :table_rank: 2
27
+ :elo_increment:
28
+ :elo_reached:
29
+ :penalty_clock: false
30
+ :penalty_leave: false
31
+ - :rank: 2
30
32
  :id: 93167144
31
33
  :name: iuriadmvr1
32
34
  :score: 43
33
- :win_points: ''
34
- :game_rank:
35
+ :elo_increment:
36
+ :elo_reached:
37
+ :penalty_clock: false
38
+ :penalty_leave: false
35
39
  :game_conceded: false