ehbrs_ruby_utils 0.31.0 → 0.33.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 +4 -4
- data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/base/format_option.rb +22 -0
- data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/base/format_player.rb +27 -0
- data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/base.rb +68 -0
- data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/beginning/format_player.rb +24 -0
- data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/beginning.rb +35 -0
- data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/ending/format_player.rb +32 -0
- data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/ending.rb +45 -0
- data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters.rb +13 -0
- data/lib/ehbrs_ruby_utils/cooking_book/build/base_page.rb +42 -0
- data/lib/ehbrs_ruby_utils/cooking_book/build/index_page.rb +26 -0
- data/lib/ehbrs_ruby_utils/cooking_book/build/recipe_page.rb +26 -0
- data/lib/ehbrs_ruby_utils/cooking_book/build.rb +45 -0
- data/lib/ehbrs_ruby_utils/cooking_book/project.rb +31 -0
- data/lib/ehbrs_ruby_utils/cooking_book/recipe/ingredient.rb +21 -0
- data/lib/ehbrs_ruby_utils/cooking_book/recipe/measure.rb +60 -0
- data/lib/ehbrs_ruby_utils/cooking_book/recipe/part.rb +32 -0
- data/lib/ehbrs_ruby_utils/cooking_book/recipe.rb +37 -0
- data/lib/ehbrs_ruby_utils/cooking_book.rb +9 -0
- data/lib/ehbrs_ruby_utils/gjt1/manager.rb +8 -5
- data/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/lib/ehbrs_ruby_utils/vg/wii/file_move.rb +89 -0
- data/lib/ehbrs_ruby_utils/vg/wii/game_file.rb +87 -0
- data/lib/ehbrs_ruby_utils/vg/wii/wit/image_format.rb +47 -0
- data/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump.rb +67 -0
- data/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/info.rb +39 -0
- data/lib/ehbrs_ruby_utils/vg/wii/wit/path.rb +55 -0
- data/lib/ehbrs_ruby_utils/vg/wii/wit.rb +13 -0
- data/lib/ehbrs_ruby_utils/vg/wii.rb +11 -0
- data/lib/ehbrs_ruby_utils/vg.rb +9 -0
- data/spec/lib/ehbrs_ruby_utils/cooking_book/recipe/measure_spec.rb +21 -0
- data/spec/lib/ehbrs_ruby_utils/vg/wii/game_file_spec.rb +21 -0
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec.rb +11 -0
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/pikmin2_R92P01_wia.source.witdump +27 -0
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/pikmin2_R92P01_wia.target.yaml +22 -0
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/pikmin2_pal_iso.source.witdump +28 -0
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/pikmin2_pal_iso.target.yaml +21 -0
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/resident_evil_code_veronica_disc2_iso.source.witdump +16 -0
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/resident_evil_code_veronica_disc2_iso.target.yaml +19 -0
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/super_mario_galaxy_wbfs.source.witdump +28 -0
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/super_mario_galaxy_wbfs.target.yaml +23 -0
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/path_spec.rb +33 -0
- metadata +104 -62
- data/lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter/format_option.rb +0 -18
- data/lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter/format_player.rb +0 -30
- data/lib/ehbrs_ruby_utils/bga/table_whatsapp_formatter.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05a500e93163dbff946466f1e0500eb191734c6dab6f7ee221df9c6f7b1d652a
|
4
|
+
data.tar.gz: 551a4cd6c774196401f2c87a7b176c7e8b3ca3c94ae9b030ab16dc73a14f3555
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 652775ab4e50bdfc1066d11cab55e66fa9a5f98c670ec12cf0e7f2652b9668d5ce2c98a8a2e58faf20d433a8342a824296da1e05a34e99a516f787227ae2431b
|
7
|
+
data.tar.gz: 4be18d9b6f3641869a415e957a7ead726bec9d846c36d1ec893047b1be04a24217603388fda5c900910eb3aeba7ff86e6cd40ecae4547a01ad3ce481e286208d
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module Bga
|
7
|
+
class Table
|
8
|
+
module WhatsappFormatters
|
9
|
+
class Base
|
10
|
+
class FormatOption
|
11
|
+
acts_as_instance_method
|
12
|
+
common_constructor :table_formatter, :option
|
13
|
+
|
14
|
+
def result
|
15
|
+
"*#{option.label}:* #{option.value}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module Bga
|
7
|
+
class Table
|
8
|
+
module WhatsappFormatters
|
9
|
+
class Base
|
10
|
+
class FormatPlayer
|
11
|
+
acts_as_abstract :fields
|
12
|
+
acts_as_instance_method
|
13
|
+
common_constructor :table_formatter, :player
|
14
|
+
|
15
|
+
FIELD_SEPARATOR = ' - '
|
16
|
+
|
17
|
+
delegate :name, to: :player
|
18
|
+
|
19
|
+
def result
|
20
|
+
fields.map { |v| send(v) }.join(FIELD_SEPARATOR)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module Bga
|
7
|
+
class Table
|
8
|
+
module WhatsappFormatters
|
9
|
+
class Base
|
10
|
+
acts_as_abstract :players_title, :root_items_title, :title_icon
|
11
|
+
enable_simple_cache
|
12
|
+
common_constructor :table
|
13
|
+
|
14
|
+
PLAYERS_EXTRA = ''
|
15
|
+
ROOT_ITENS = {
|
16
|
+
'Jogo' => :game_name,
|
17
|
+
'Criada em' => :creation_time,
|
18
|
+
'Duração' => :estimated_duration,
|
19
|
+
'Endereço' => :url
|
20
|
+
}.freeze
|
21
|
+
SECTION_SEPARATOR = "\n\n"
|
22
|
+
|
23
|
+
# @return [Pathname]
|
24
|
+
def image_local_path
|
25
|
+
table.game.box_large_image.local_path
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
[root_items_to_s, players_to_s, options_to_s].map(&:strip).join(SECTION_SEPARATOR)
|
30
|
+
end
|
31
|
+
|
32
|
+
def root_items_to_s
|
33
|
+
title_to_s(root_items_title) + ROOT_ITENS.map { |k, v| "*#{k}*: #{table.send(v)}" }
|
34
|
+
.join("\n")
|
35
|
+
end
|
36
|
+
|
37
|
+
def options_to_s
|
38
|
+
title_to_s('Opções') + options.join("\n")
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [String]
|
42
|
+
def players_extra
|
43
|
+
PLAYERS_EXTRA
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [String]
|
47
|
+
def players_to_s
|
48
|
+
title_to_s(players_title) + players_extra + players.join("\n")
|
49
|
+
end
|
50
|
+
|
51
|
+
def title_to_s(title)
|
52
|
+
'*' + [title_icon, title, title_icon].join(' ') + "*\n\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def players
|
56
|
+
table.players.map { |player| format_player(player) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def options
|
60
|
+
table.options.map { |player| format_option(player) }
|
61
|
+
end
|
62
|
+
|
63
|
+
require_sub __FILE__, require_mode: :kernel
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/bga/table/whatsapp_formatters/base/format_player'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Bga
|
8
|
+
class Table
|
9
|
+
module WhatsappFormatters
|
10
|
+
class Beginning < ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters::Base
|
11
|
+
class FormatPlayer < ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters::Base::FormatPlayer
|
12
|
+
acts_as_instance_method
|
13
|
+
|
14
|
+
FIELDS = %w[name].freeze
|
15
|
+
|
16
|
+
def fields
|
17
|
+
FIELDS
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/bga/table/whatsapp_formatters/base'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Bga
|
8
|
+
class Table
|
9
|
+
module WhatsappFormatters
|
10
|
+
class Beginning < ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters::Base
|
11
|
+
PLAYERS_TITLE = 'Jogadores'
|
12
|
+
ROOT_ITEMS_TITLE = 'Mesa iniciada'
|
13
|
+
TITLE_ICON = 0x2694.chr(::Encoding::UTF_8)
|
14
|
+
|
15
|
+
# @return [String]
|
16
|
+
def players_title
|
17
|
+
PLAYERS_TITLE
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [String]
|
21
|
+
def root_items_title
|
22
|
+
ROOT_ITEMS_TITLE
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
def title_icon
|
27
|
+
TITLE_ICON
|
28
|
+
end
|
29
|
+
|
30
|
+
require_sub __FILE__, require_mode: :kernel
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/bga/table/whatsapp_formatters/base/format_player'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Bga
|
8
|
+
class Table
|
9
|
+
module WhatsappFormatters
|
10
|
+
class Ending < ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters::Base
|
11
|
+
class FormatPlayer < ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters::Base::FormatPlayer
|
12
|
+
acts_as_instance_method
|
13
|
+
|
14
|
+
FIELDS = %w[table_rank name score].freeze
|
15
|
+
|
16
|
+
def fields
|
17
|
+
FIELDS
|
18
|
+
end
|
19
|
+
|
20
|
+
def table_rank
|
21
|
+
"*#{player.rank}º*"
|
22
|
+
end
|
23
|
+
|
24
|
+
def score
|
25
|
+
"⭐ #{player.score}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/bga/table/whatsapp_formatters/base'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Bga
|
8
|
+
class Table
|
9
|
+
module WhatsappFormatters
|
10
|
+
class Ending < ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters::Base
|
11
|
+
PLAYERS_TITLE = 'Resultado'
|
12
|
+
ROOT_ITEMS_TITLE = 'Mesa terminada'
|
13
|
+
TITLE_ICON = 0x1F3C6.chr(::Encoding::UTF_8)
|
14
|
+
|
15
|
+
# @return [String]
|
16
|
+
def game_conceded_to_s
|
17
|
+
table.game_conceded? ? "*Derrota admitida*\n\n" : ''
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [String]
|
21
|
+
def players_extra
|
22
|
+
game_conceded_to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
def players_title
|
27
|
+
PLAYERS_TITLE
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String]
|
31
|
+
def root_items_title
|
32
|
+
ROOT_ITEMS_TITLE
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String]
|
36
|
+
def title_icon
|
37
|
+
TITLE_ICON
|
38
|
+
end
|
39
|
+
|
40
|
+
require_sub __FILE__, require_mode: :kernel
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module CookingBook
|
7
|
+
class Build
|
8
|
+
class BasePage < SimpleDelegator
|
9
|
+
attr_reader :parent
|
10
|
+
|
11
|
+
def initialize(parent, source_object)
|
12
|
+
super(source_object)
|
13
|
+
@parent = parent
|
14
|
+
end
|
15
|
+
|
16
|
+
def build
|
17
|
+
target_path.write(target_content)
|
18
|
+
end
|
19
|
+
|
20
|
+
def href
|
21
|
+
"#{target_basename}.html"
|
22
|
+
end
|
23
|
+
|
24
|
+
def target_path
|
25
|
+
parent.target_dir.join(href)
|
26
|
+
end
|
27
|
+
|
28
|
+
def target_content
|
29
|
+
erb_result('layout', ::EhbrsRubyUtils::CookingBook::Build::BasePage)
|
30
|
+
end
|
31
|
+
|
32
|
+
def inner_content
|
33
|
+
erb_result('inner', self.class)
|
34
|
+
end
|
35
|
+
|
36
|
+
def erb_result(template_basename, template_source = self)
|
37
|
+
template_source.erb_template("#{template_basename}.html.erb", self)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/cooking_book/build/base_page'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module CookingBook
|
8
|
+
class Build
|
9
|
+
class IndexPage < ::EhbrsRubyUtils::CookingBook::Build::BasePage
|
10
|
+
TITLE = 'Início'
|
11
|
+
|
12
|
+
def initialize(parent)
|
13
|
+
super(parent, nil)
|
14
|
+
end
|
15
|
+
|
16
|
+
def target_basename
|
17
|
+
'index'
|
18
|
+
end
|
19
|
+
|
20
|
+
def title
|
21
|
+
TITLE
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/cooking_book/build/base_page'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module CookingBook
|
8
|
+
class Build
|
9
|
+
class RecipePage < ::EhbrsRubyUtils::CookingBook::Build::BasePage
|
10
|
+
def target_basename
|
11
|
+
title.variableize
|
12
|
+
end
|
13
|
+
|
14
|
+
def parts
|
15
|
+
@parts ||= super.map { |e| Part.new(e) }
|
16
|
+
end
|
17
|
+
|
18
|
+
class Part < SimpleDelegator
|
19
|
+
def content
|
20
|
+
::EhbrsRubyUtils::CookingBook::Build::RecipePage.erb_template('part.html.erb', self)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/fs/clearable_directory'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module CookingBook
|
8
|
+
class Build
|
9
|
+
require_sub __FILE__
|
10
|
+
enable_simple_cache
|
11
|
+
enable_listable
|
12
|
+
lists.add_symbol :option, :target_dir
|
13
|
+
|
14
|
+
common_constructor :project, :options, default: [{}] do
|
15
|
+
self.options = self.class.lists.option.hash_keys_validate!(options.symbolize_keys)
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
target_dir.clear
|
20
|
+
index_page.build
|
21
|
+
recipes_pages.each(&:build)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def index_page_uncached
|
27
|
+
::EhbrsRubyUtils::CookingBook::Build::IndexPage.new(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def recipes_pages_uncached
|
31
|
+
project.recipes.map do |recipe|
|
32
|
+
::EhbrsRubyUtils::CookingBook::Build::RecipePage.new(self, recipe)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def target_dir_uncached
|
37
|
+
::EacRubyUtils::Fs::ClearableDirectory.new(options[OPTION_TARGET_DIR] || default_target_dir)
|
38
|
+
end
|
39
|
+
|
40
|
+
def default_target_dir
|
41
|
+
project.root.join('dist')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/cooking_book/recipe'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module CookingBook
|
8
|
+
class Project
|
9
|
+
RECIPES_ROOT_SUBPATH = 'recipes'
|
10
|
+
|
11
|
+
enable_simple_cache
|
12
|
+
common_constructor :root do
|
13
|
+
self.root = root.to_pathname
|
14
|
+
end
|
15
|
+
|
16
|
+
delegate :to_s, to: :root
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def recipes_root_uncached
|
21
|
+
root.join(RECIPES_ROOT_SUBPATH)
|
22
|
+
end
|
23
|
+
|
24
|
+
def recipes_uncached
|
25
|
+
::Dir.glob(File.join('**', '*.{yml,yaml}'), base: recipes_root.to_path).map do |subpath|
|
26
|
+
::EhbrsRubyUtils::CookingBook::Recipe.from_file(recipes_root.join(subpath))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/cooking_book/recipe/measure'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module CookingBook
|
8
|
+
class Recipe
|
9
|
+
class Ingredient
|
10
|
+
class << self
|
11
|
+
def build(label, value)
|
12
|
+
new(label, ::EhbrsRubyUtils::CookingBook::Recipe::Measure.build(value))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
enable_simple_cache
|
17
|
+
common_constructor :name, :measure
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/yaml'
|
5
|
+
require 'ehbrs_ruby_utils/cooking_book/recipe/ingredient'
|
6
|
+
|
7
|
+
module EhbrsRubyUtils
|
8
|
+
module CookingBook
|
9
|
+
class Recipe
|
10
|
+
class Measure
|
11
|
+
FLOAT_PATTERN = /\d+(?:\.\d+)?/.freeze
|
12
|
+
FRACTION_PATTERN = %r{(#{FLOAT_PATTERN})(?:\s*/\s*(#{FLOAT_PATTERN}))?}.freeze
|
13
|
+
QUANTITY_UNIT_PATTERN = /\A#{FRACTION_PATTERN}(?:\s*(\S+))?\z/.freeze
|
14
|
+
VARIABLE_PATTERN = /\A\~\z/.freeze
|
15
|
+
VARIABLE_TEXT = 'a gosto'
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def build(value)
|
19
|
+
value = value.to_s.strip
|
20
|
+
build_from_variable(value) || build_from_pattern(value) || build_unknown(value)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def build_from_variable(value)
|
26
|
+
VARIABLE_PATTERN.if_match(value, false) do
|
27
|
+
new(nil, nil, nil)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_from_pattern(value)
|
32
|
+
QUANTITY_UNIT_PATTERN.if_match(value, false) do |m|
|
33
|
+
new(m[1].if_present(&:to_f), m[2].if_present(&:to_f), m[3])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_unknown(value)
|
38
|
+
new(nil, nil, "unknown format: |#{value}|")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
common_constructor :numerator, :denominator, :unit
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
return VARIABLE_TEXT if variable?
|
46
|
+
|
47
|
+
"#{quantity_to_s} #{unit}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def quantity_to_s
|
51
|
+
numerator.to_s + (denominator.if_present('') { |v| "/ #{v}" })
|
52
|
+
end
|
53
|
+
|
54
|
+
def variable?
|
55
|
+
numerator.blank?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/yaml'
|
5
|
+
require 'ehbrs_ruby_utils/cooking_book/recipe/ingredient'
|
6
|
+
|
7
|
+
module EhbrsRubyUtils
|
8
|
+
module CookingBook
|
9
|
+
class Recipe
|
10
|
+
class Part
|
11
|
+
enable_simple_cache
|
12
|
+
common_constructor :title, :source_data
|
13
|
+
|
14
|
+
def notes
|
15
|
+
source_data[:notes]
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def ingredients_uncached
|
21
|
+
source_data.fetch(:ingredients).map do |label, value|
|
22
|
+
::EhbrsRubyUtils::CookingBook::Recipe::Ingredient.build(label, value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def steps_uncached
|
27
|
+
source_data.fetch(:steps)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/yaml'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module CookingBook
|
8
|
+
class Recipe
|
9
|
+
enable_simple_cache
|
10
|
+
require_sub __FILE__
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def from_file(path)
|
14
|
+
new(::EacRubyUtils::Yaml.load_file(path))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
common_constructor :source_data do
|
19
|
+
self.source_data = source_data.deep_symbolize_keys
|
20
|
+
end
|
21
|
+
|
22
|
+
def title
|
23
|
+
source_data.fetch(:title)
|
24
|
+
end
|
25
|
+
|
26
|
+
def notes
|
27
|
+
source_data[:notes]
|
28
|
+
end
|
29
|
+
|
30
|
+
def parts
|
31
|
+
@parts ||= source_data.fetch(:parts).map do |k, v|
|
32
|
+
::EhbrsRubyUtils::CookingBook::Recipe::Part.new(k, v)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -11,11 +11,14 @@ module EhbrsRubyUtils
|
|
11
11
|
include ::Singleton
|
12
12
|
acts_as_abstract :bga_usernam, :bga_password, :whatsapp_recipient
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
%w[beginning ending].each do |type|
|
15
|
+
# @param table [EhbrsRubyUtils::Bga::Table]
|
16
|
+
# @return [void]
|
17
|
+
define_method "bga_table_#{type}_notify" do |table|
|
18
|
+
formatter = ::EhbrsRubyUtils::Bga::Table::WhatsappFormatters.const_get(type.camelize)
|
19
|
+
.new(table)
|
20
|
+
whatsapp_send(formatter.to_s, formatter.image_local_path)
|
21
|
+
end
|
19
22
|
end
|
20
23
|
|
21
24
|
def on_bga_logged_session(&block)
|