ehbrs_ruby_utils 0.27.0 → 0.28.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: a5dec5f4f8ddd8f557593ebf6996da07a0068037d60b944d7dd026df93ad41bd
4
- data.tar.gz: d13e4169174f00b947f1c057112d7390ded0322266f24a36df38bc623441c0e2
3
+ metadata.gz: 242dda28e0e3dab83a2b68d030273e0335b54f45a070980bcd7de340fdb53f1e
4
+ data.tar.gz: 76442e6655256f61039a009e53b241023e01b2e592bb42227d113ab81105430d
5
5
  SHA512:
6
- metadata.gz: 9b6f2c93327cfaeedef1a4e73636cd39818d0c65ced4e8573089c91bc4b96dc8e27b471676a8546adef346140db32eaf8d84f3e1a81012a1cfc711e22f348059
7
- data.tar.gz: 5e8b0aa58cdbd8e75cf53296ff0b8936093f333131293fbcf37ff890b3ae6398a5f14b79b6a04308f9906f0f50bc8e52a9548d4e676dd9859fd64ea7e0ac26d0
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,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ehbrs_ruby_utils/bga/game'
4
+ require 'ehbrs_ruby_utils/bga/parsers/table'
3
5
  require 'ehbrs_ruby_utils/bga/parsers/table/options'
4
6
  require 'ehbrs_ruby_utils/bga/urls'
5
7
  require 'eac_ruby_utils/core_ext'
@@ -32,6 +34,11 @@ module EhbrsRubyUtils
32
34
 
33
35
  private
34
36
 
37
+ # @return [EhbrsRubyUtils::Bga::Game]
38
+ def game_uncached
39
+ ::EhbrsRubyUtils::Bga::Game.new(game_code)
40
+ end
41
+
35
42
  SET_ITEMS.each do |item|
36
43
  define_method "#{item}_uncached" do
37
44
  data.fetch(item).map do |item_data|
@@ -21,9 +21,9 @@ module EhbrsRubyUtils
21
21
  }.freeze
22
22
  SECTION_SEPARATOR = "\n\n"
23
23
 
24
- def perform
25
- infov 'Fetching table', table_id
26
- infov 'Message', "<<<EOS\n#{to_message}\nEOS\n"
24
+ # @return [Pathname]
25
+ def image_local_path
26
+ table.game.box_large_image.local_path
27
27
  end
28
28
 
29
29
  def to_s
@@ -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.0'
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.0
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-09 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
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0.77'
67
+ version: '0.78'
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0.77'
74
+ version: '0.78'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: dentaku
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -393,50 +398,50 @@ signing_key:
393
398
  specification_version: 4
394
399
  summary: Utilities for EHB/RS's Ruby projects.
395
400
  test_files:
396
- - spec/spec_helper.rb
397
- - spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec.rb
398
- - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_attachment.target.yaml
399
- - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_subtitle.target.yaml
400
- - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_attachment.source.yaml
401
- - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_video.source.yaml
402
- - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_subtitle.source.yaml
403
- - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_video.target.yaml
404
- - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_audio.target.yaml
405
- - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_audio.source.yaml
406
- - spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb
407
- - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec.rb
408
- - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec.rb
409
- - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.target.yaml
410
- - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.target.yaml
411
- - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.source.html
412
- - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.source.html
413
- - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.source.html
414
- - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.target.yaml
415
- - spec/lib/ehbrs_ruby_utils/videos/stream_spec.rb
401
+ - spec/rubocop_check_spec.rb
416
402
  - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_308782287.target.yaml
417
- - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_368448439.target.yaml
418
- - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_356513708.source.html
419
- - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_357408039.source.html
420
403
  - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_356513708.target.yaml
421
- - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373747455.target.yaml
422
404
  - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_302873643.target.yaml
423
- - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373747455.source.html
424
- - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_302873643.source.html
425
- - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373602409.target.yaml
426
- - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_308782287.source.html
405
+ - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_368448439.target.yaml
427
406
  - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_368448439.source.html
407
+ - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_357408039.source.html
408
+ - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_356513708.source.html
409
+ - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373747455.source.html
428
410
  - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373602409.source.html
411
+ - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373602409.target.yaml
412
+ - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_302873643.source.html
429
413
  - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_357408039.target.yaml
430
- - spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/1.source.html
414
+ - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_308782287.source.html
415
+ - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373747455.target.yaml
431
416
  - spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/2.target.yaml
432
- - spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/1.target.yaml
433
417
  - spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/2.source.html
418
+ - spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/1.source.html
419
+ - spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/1.target.yaml
434
420
  - spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec.rb
435
421
  - spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec.rb
436
- - spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/minimum.source.yaml
422
+ - spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec.rb
437
423
  - spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/minimum.target.yaml
438
- - spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/ehbrs_music1.target.yaml
439
424
  - spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/ehbrs_music1.source.yaml
440
- - spec/rubocop_check_spec.rb
425
+ - spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/minimum.source.yaml
426
+ - spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/ehbrs_music1.target.yaml
427
+ - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.target.yaml
428
+ - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.source.html
429
+ - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec.rb
430
+ - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec.rb
431
+ - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.source.html
432
+ - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.target.yaml
433
+ - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.source.html
434
+ - spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.target.yaml
435
+ - spec/lib/ehbrs_ruby_utils/videos/stream_spec.rb
436
+ - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_audio.target.yaml
437
+ - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_video.target.yaml
438
+ - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_attachment.target.yaml
439
+ - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_subtitle.target.yaml
440
+ - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_audio.source.yaml
441
+ - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_attachment.source.yaml
442
+ - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_subtitle.source.yaml
443
+ - spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_video.source.yaml
444
+ - spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb
445
+ - spec/spec_helper.rb
441
446
  - ".rubocop.yml"
442
447
  - ".rspec"