ehbrs_ruby_utils 0.27.1 → 0.28.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs_ruby_utils/bga/game/image.rb +40 -0
- data/lib/ehbrs_ruby_utils/bga/game.rb +40 -0
- data/lib/ehbrs_ruby_utils/bga/parsers/table.rb +11 -2
- data/lib/ehbrs_ruby_utils/bga/table.rb +6 -0
- data/lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb +5 -0
- data/lib/ehbrs_ruby_utils/bga.rb +9 -0
- data/lib/ehbrs_ruby_utils/gjt1/manager.rb +46 -0
- data/lib/ehbrs_ruby_utils/gjt1.rb +9 -0
- data/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_302873643.target.yaml +1 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_308782287.target.yaml +1 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_356513708.target.yaml +1 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_357408039.target.yaml +1 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_368448439.target.yaml +1 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373602409.target.yaml +1 -0
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373747455.target.yaml +1 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 242dda28e0e3dab83a2b68d030273e0335b54f45a070980bcd7de340fdb53f1e
|
4
|
+
data.tar.gz: 76442e6655256f61039a009e53b241023e01b2e592bb42227d113ab81105430d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
29
|
-
|
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,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
|
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.
|
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-
|
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
|