ehbrs_ruby_utils 0.27.1 → 0.28.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c871abaf7dc4060d3d4165e5e0ac29e083ff688c87972b008578ad7c6ee3b51c
4
- data.tar.gz: 56a62fcdb9ac75d7e5fed15c145dd14b36b207628499108781337b870001147a
3
+ metadata.gz: 242dda28e0e3dab83a2b68d030273e0335b54f45a070980bcd7de340fdb53f1e
4
+ data.tar.gz: 76442e6655256f61039a009e53b241023e01b2e592bb42227d113ab81105430d
5
5
  SHA512:
6
- metadata.gz: 238cdc34f19c2b8c45ef4280ddac58f0f10ac6354df28c6d3fadf6d52999f4cfd7c4464c36e8b2c3353dcb11dae5bbb56f29d4fc9c110cea960d2d259952cc9c
7
- data.tar.gz: 0d6a2de37a8b40a4005b6dd6cd9363f4a7f730bf4e474307e15939ce5d902ab7ccfe1bce6e7f4f04d9021f7201783e7d58ad10c51adc17a85c33b9aca282ddca
6
+ metadata.gz: 3dc4de45f3322ab74030397d7440c3d6fe226d6f7d15ac93fec21846f6281975855344432c60a909ae8a01e222afb206dffc0ad91ee63f2a683b1749b053e93a
7
+ data.tar.gz: 0df77e54c42753a50ff8fab054e18dd5ae27593036cbb6cefca2aea45d1e21fe012a34163f2660b4c120618360525d0f46174c63d397faa556eb97e0eab4a9ed
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Bga
7
+ class Game
8
+ class Image
9
+ common_constructor :game, :suffix
10
+
11
+ IMAGE_URL_PREFIX = 'https://x.boardgamearena.net/data/gamemedia/'
12
+
13
+ # @return [String]
14
+ def fs_object_id
15
+ [game.code, suffix].map(&:parameterize)
16
+ end
17
+
18
+ # @param suffix [String]
19
+ # @return [Pathname]
20
+ def local_path
21
+ download_to_cache unless fs_cache.stored?
22
+ fs_cache.content_path.to_pathname
23
+ end
24
+
25
+ # @return [Addressable::URI]
26
+ def url
27
+ "#{IMAGE_URL_PREFIX}#{game.code}#{suffix}".to_uri
28
+ end
29
+
30
+ private
31
+
32
+ # @return [void]
33
+ def download_to_cache
34
+ fs_cache.send(:assert_directory_on_path)
35
+ ::EacEnvs::Http::Request.new.url(url).response.write_body(fs_cache.content_path)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Bga
7
+ class Game
8
+ common_constructor :code
9
+
10
+ # @param suffix [String]
11
+ # @return [EhbrsRubyUtils::Bga::Game::Image]
12
+ def image(suffix)
13
+ ::EhbrsRubyUtils::Bga::Game::Image.new(self, suffix)
14
+ end
15
+
16
+ {
17
+ publisher: '/publisher/0.png',
18
+ banner_medium: '/banner/default_500.jpg',
19
+ banner_large: '/banner/default.jpg',
20
+ box_small: '/box/en_75.png',
21
+ box_medium: '/box/en_180.png',
22
+ box_large: '/box/en_280.png',
23
+ title_medium: '/title/en_500.png',
24
+ title_large: '/title/en_2000.png'
25
+ }.each do |k, suffix|
26
+ define_method "#{k}_image" do
27
+ image(suffix)
28
+ end
29
+ end
30
+
31
+ # @param nth [Integer]
32
+ # @return [Addressable::URI]
33
+ def display_image(nth)
34
+ image("/display/#{nth}.jpg")
35
+ end
36
+
37
+ require_sub __FILE__
38
+ end
39
+ end
40
+ end
@@ -7,8 +7,10 @@ module EhbrsRubyUtils
7
7
  module Bga
8
8
  module Parsers
9
9
  class Table < ::Aranha::Parsers::Html::Item
10
+ GAME_IMAGE_URL_PARSER = %r{/gamemedia/([^/]+)/box/}.to_parser { |m| m[1] }
10
11
  ITEM_XPATH = '/'
11
12
 
13
+ field :game_code, :string, '//meta[@property="og:image"]/@content'
12
14
  field :game_name, :string, './/*[@id = "table_name"]/text()'
13
15
  field :creation_time, :string, './/*[@id = "creationtime"]/text()'
14
16
  field :estimated_duration, :string, './/*[@id = "estimated_duration"]/text()'
@@ -25,8 +27,9 @@ module EhbrsRubyUtils
25
27
  %i[options players].each do |key|
26
28
  r[key] = self.class.const_get(key.to_s.camelize).from_node(r.fetch(key)).data
27
29
  end
28
- r[:creation_time] = process_creation_time(r[:creation_time])
29
- r[:game_conceded] = process_game_conceded(r[:game_conceded])
30
+ %i[creation_time game_code game_conceded].each do |key|
31
+ r[key] = send("process_#{key}", r.fetch(key))
32
+ end
30
33
  r
31
34
  end
32
35
 
@@ -36,6 +39,12 @@ module EhbrsRubyUtils
36
39
  creation_time.gsub('Criado:', '').strip
37
40
  end
38
41
 
42
+ # @param node [String]
43
+ # @return [String]
44
+ def process_game_code(image_url)
45
+ GAME_IMAGE_URL_PARSER.parse!(image_url)
46
+ end
47
+
39
48
  # @param node [Nokogiri::XML::Element]
40
49
  # @return [Boolean]
41
50
  def process_game_conceded(node)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ehbrs_ruby_utils/bga/game'
3
4
  require 'ehbrs_ruby_utils/bga/parsers/table'
4
5
  require 'ehbrs_ruby_utils/bga/parsers/table/options'
5
6
  require 'ehbrs_ruby_utils/bga/urls'
@@ -33,6 +34,11 @@ module EhbrsRubyUtils
33
34
 
34
35
  private
35
36
 
37
+ # @return [EhbrsRubyUtils::Bga::Game]
38
+ def game_uncached
39
+ ::EhbrsRubyUtils::Bga::Game.new(game_code)
40
+ end
41
+
36
42
  SET_ITEMS.each do |item|
37
43
  define_method "#{item}_uncached" do
38
44
  data.fetch(item).map do |item_data|
@@ -21,6 +21,11 @@ module EhbrsRubyUtils
21
21
  }.freeze
22
22
  SECTION_SEPARATOR = "\n\n"
23
23
 
24
+ # @return [Pathname]
25
+ def image_local_path
26
+ table.game.box_large_image.local_path
27
+ end
28
+
24
29
  def to_s
25
30
  [root_items_to_s, players_to_s, options_to_s].map(&:strip).join(SECTION_SEPARATOR)
26
31
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Bga
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs_ruby_utils/bga/session'
4
+ require 'ehbrs_ruby_utils/executables'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EhbrsRubyUtils
8
+ module Gjt1
9
+ class Manager
10
+ include ::Singleton
11
+ acts_as_abstract :bga_usernam, :bga_password, :whatsapp_recipient
12
+
13
+ def on_bga_logged_session(&block)
14
+ bga_session = new_bga_session
15
+ begin
16
+ bga_session.on_logged { block.call(bga_session) }
17
+ ensure
18
+ bga_session.close
19
+ bga_session = nil
20
+ end
21
+ end
22
+
23
+ # @return [EhbrsRubyUtils::Bga::Session] Cria uma nova sessão BGA.
24
+ def new_bga_session
25
+ ::EhbrsRubyUtils::Bga::Session.new(bga_username, bga_password)
26
+ end
27
+
28
+ # @param message [String]
29
+ # @param image_path [Pathname]
30
+ # @return [void]
31
+ def whatsapp_send(message, image_path = nil)
32
+ if image_path.present?
33
+ mudslide_run('send-image', '--caption', message, whatsapp_recipient, image_path)
34
+ else
35
+ mudslide_run('send', whatsapp_recipient, message)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def mudslide_run(*args)
42
+ ::EhbrsRubyUtils::Executables.mudslide.command(*args).system!
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Gjt1
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.27.1'
4
+ VERSION = '0.28.0'
5
5
  end
@@ -1,4 +1,5 @@
1
1
  ---
2
+ :game_code: puertorico
2
3
  :game_name: Puerto Rico
3
4
  :creation_time: 24/09/2022 às 22:41
4
5
  :estimated_duration: 2h31
@@ -1,4 +1,5 @@
1
1
  ---
2
+ :game_code: thecrew
2
3
  :game_name: A Tripulação (The Crew)
3
4
  :creation_time: 15/10/2022 às 17:49
4
5
  :estimated_duration: 3.6 dias
@@ -1,4 +1,5 @@
1
1
  ---
2
+ :game_code: puertorico
2
3
  :game_name: Puerto Rico
3
4
  :creation_time: 14/03/2023 às 08:36
4
5
  :estimated_duration: 35 dias
@@ -1,4 +1,5 @@
1
1
  ---
2
+ :game_code: puertorico
2
3
  :game_name: Puerto Rico
3
4
  :creation_time: 16/03/2023 às 22:13
4
5
  :estimated_duration: 35 dias
@@ -1,4 +1,5 @@
1
1
  ---
2
+ :game_code: puertorico
2
3
  :game_name: Puerto Rico
3
4
  :creation_time: 18/04/2023 às 16:25
4
5
  :estimated_duration: 24 dias
@@ -1,4 +1,5 @@
1
1
  ---
2
+ :game_code: quoridor
2
3
  :game_name: Quoridor
3
4
  :creation_time: 03/05/2023 às 23:40
4
5
  :estimated_duration: 5 dias
@@ -1,4 +1,5 @@
1
1
  ---
2
+ :game_code: koikoi
2
3
  :game_name: Koi-koi
3
4
  :creation_time: 04/05/2023 às 11:13
4
5
  :estimated_duration: 5 dias
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehbrs_ruby_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.1
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-10 00:00:00.000000000 Z
11
+ date: 2023-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha
@@ -231,6 +231,9 @@ files:
231
231
  - ".rspec"
232
232
  - ".rubocop.yml"
233
233
  - lib/ehbrs_ruby_utils.rb
234
+ - lib/ehbrs_ruby_utils/bga.rb
235
+ - lib/ehbrs_ruby_utils/bga/game.rb
236
+ - lib/ehbrs_ruby_utils/bga/game/image.rb
234
237
  - lib/ehbrs_ruby_utils/bga/parsers/game_stats.rb
235
238
  - lib/ehbrs_ruby_utils/bga/parsers/game_stats/players.rb
236
239
  - lib/ehbrs_ruby_utils/bga/parsers/table.rb
@@ -264,6 +267,8 @@ files:
264
267
  - lib/ehbrs_ruby_utils/fs/selected.rb
265
268
  - lib/ehbrs_ruby_utils/fs/selected/build.rb
266
269
  - lib/ehbrs_ruby_utils/fs/selected/build_file.rb
270
+ - lib/ehbrs_ruby_utils/gjt1.rb
271
+ - lib/ehbrs_ruby_utils/gjt1/manager.rb
267
272
  - lib/ehbrs_ruby_utils/music.rb
268
273
  - lib/ehbrs_ruby_utils/music/lyrics_book.rb
269
274
  - lib/ehbrs_ruby_utils/music/lyrics_book/album.rb