ehbrs_ruby_utils 0.32.0 → 0.35.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb +2 -2
  3. data/lib/ehbrs_ruby_utils/bga/parsers/table/options.rb +3 -3
  4. data/lib/ehbrs_ruby_utils/bga/session/skip_trophies.rb +1 -1
  5. data/lib/ehbrs_ruby_utils/bga/session/user.rb +1 -3
  6. data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/base.rb +1 -1
  7. data/lib/ehbrs_ruby_utils/circular_list_spreader/base_level.rb +1 -1
  8. data/lib/ehbrs_ruby_utils/circular_list_spreader/group_level.rb +1 -1
  9. data/lib/ehbrs_ruby_utils/cooking_book/build/base_page.rb +42 -0
  10. data/lib/ehbrs_ruby_utils/cooking_book/build/index_page.rb +26 -0
  11. data/lib/ehbrs_ruby_utils/cooking_book/build/recipe_page.rb +26 -0
  12. data/lib/ehbrs_ruby_utils/cooking_book/build.rb +45 -0
  13. data/lib/ehbrs_ruby_utils/cooking_book/project.rb +31 -0
  14. data/lib/ehbrs_ruby_utils/cooking_book/recipe/ingredient.rb +21 -0
  15. data/lib/ehbrs_ruby_utils/cooking_book/recipe/measure.rb +60 -0
  16. data/lib/ehbrs_ruby_utils/cooking_book/recipe/part.rb +32 -0
  17. data/lib/ehbrs_ruby_utils/cooking_book/recipe.rb +37 -0
  18. data/lib/ehbrs_ruby_utils/cooking_book.rb +9 -0
  19. data/lib/ehbrs_ruby_utils/fs/selected/build.rb +1 -1
  20. data/lib/ehbrs_ruby_utils/music/lyrics_book/resource.rb +1 -1
  21. data/lib/ehbrs_ruby_utils/patches/object/template.rb +2 -2
  22. data/lib/ehbrs_ruby_utils/patches/object.rb +1 -1
  23. data/lib/ehbrs_ruby_utils/patches.rb +1 -1
  24. data/lib/ehbrs_ruby_utils/version.rb +1 -1
  25. data/lib/ehbrs_ruby_utils/vg/wii/file_move.rb +89 -0
  26. data/lib/ehbrs_ruby_utils/vg/wii/game_file.rb +87 -0
  27. data/lib/ehbrs_ruby_utils/vg/wii/wit/image_format.rb +47 -0
  28. data/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump.rb +67 -0
  29. data/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/info.rb +39 -0
  30. data/lib/ehbrs_ruby_utils/vg/wii/wit/path.rb +55 -0
  31. data/lib/ehbrs_ruby_utils/vg/wii/wit.rb +13 -0
  32. data/lib/ehbrs_ruby_utils/vg/wii.rb +11 -0
  33. data/lib/ehbrs_ruby_utils/vg.rb +9 -0
  34. data/lib/ehbrs_ruby_utils/videos/container.rb +1 -1
  35. data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors/subtitles_provider.rb +51 -0
  36. data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors/title.rb +5 -0
  37. data/lib/ehbrs_ruby_utils/videos/quality.rb +1 -3
  38. data/lib/ehbrs_ruby_utils/videos/resolution.rb +2 -2
  39. data/lib/ehbrs_ruby_utils/videos/series/rename/file/basename_parser.rb +2 -2
  40. data/lib/ehbrs_ruby_utils/videos/series/rename/file.rb +2 -2
  41. data/lib/ehbrs_ruby_utils/videos/series/rename/line_result.rb +2 -2
  42. data/lib/ehbrs_ruby_utils/videos/series/rename/line_result_group.rb +1 -0
  43. data/lib/ehbrs_ruby_utils/videos/series/rename/season_group.rb +1 -0
  44. data/lib/ehbrs_ruby_utils/videos/stream.rb +1 -1
  45. data/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +1 -1
  46. metadata +44 -146
  47. data/.rspec +0 -1
  48. data/.rubocop.yml +0 -45
  49. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec.rb +0 -7
  50. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-12.source.html +0 -8657
  51. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-12.target.yaml +0 -41
  52. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-19.source.html +0 -8650
  53. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-19.target.yaml +0 -41
  54. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93167144_2023-06-12.source.html +0 -8657
  55. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93167144_2023-06-12.target.yaml +0 -5
  56. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93205235_2023-06-12.source.html +0 -8657
  57. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93205235_2023-06-12.target.yaml +0 -13
  58. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93212034_2023-06-12.source.html +0 -8657
  59. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93212034_2023-06-12.target.yaml +0 -29
  60. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93223573_2023-06-12.source.html +0 -8657
  61. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93223573_2023-06-12.target.yaml +0 -7
  62. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93248308_2023-06-12.source.html +0 -8657
  63. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93248308_2023-06-12.target.yaml +0 -1
  64. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec.rb +0 -7
  65. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/1.source.html +0 -1082
  66. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/1.target.yaml +0 -151
  67. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/2.source.html +0 -1083
  68. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/2.target.yaml +0 -1127
  69. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec.rb +0 -7
  70. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_302873643.source.html +0 -1491
  71. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_302873643.target.yaml +0 -40
  72. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_308782287.source.html +0 -1965
  73. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_308782287.target.yaml +0 -46
  74. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_356513708.source.html +0 -1497
  75. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_356513708.target.yaml +0 -56
  76. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_357408039.source.html +0 -1500
  77. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_357408039.target.yaml +0 -66
  78. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_368448439.source.html +0 -1497
  79. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_368448439.target.yaml +0 -58
  80. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373602409.source.html +0 -1441
  81. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373602409.target.yaml +0 -30
  82. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373747455.source.html +0 -1521
  83. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373747455.target.yaml +0 -59
  84. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_383405743.source.html +0 -1480
  85. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_383405743.target.yaml +0 -32
  86. data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec.rb +0 -68
  87. data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/ehbrs_music1.source.yaml +0 -124
  88. data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/ehbrs_music1.target.yaml +0 -70
  89. data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/minimum.source.yaml +0 -7
  90. data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/minimum.target.yaml +0 -5
  91. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec.rb +0 -7
  92. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.source.html +0 -993
  93. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.target.yaml +0 -5
  94. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.source.html +0 -478
  95. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.target.yaml +0 -43
  96. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec.rb +0 -7
  97. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.source.html +0 -763
  98. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.target.yaml +0 -22
  99. data/spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb +0 -18
  100. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec.rb +0 -13
  101. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_attachment.source.yaml +0 -28
  102. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_attachment.target.yaml +0 -8
  103. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_audio.source.yaml +0 -49
  104. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_audio.target.yaml +0 -8
  105. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_subtitle.source.yaml +0 -43
  106. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_subtitle.target.yaml +0 -8
  107. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_video.source.yaml +0 -59
  108. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_video.target.yaml +0 -8
  109. data/spec/rubocop_check_spec.rb +0 -3
  110. data/spec/spec_helper.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bfa52ff0a0f148ccb210785d37954b3b3e3e991a4fb3517bb78d23bc1a683c9
4
- data.tar.gz: cc72969d634c6153c8841507fdc7582d1e004b52af6f6d6d1fc6cce0b5fff113
3
+ metadata.gz: 763112ae8325274f9c7a277a78e6984bb2c3e89632214f89d3bc3bced8e1acde
4
+ data.tar.gz: 61448a174beb1981acaa3615a923a61fc39c9bd1c615839abef486a8c716b2a4
5
5
  SHA512:
6
- metadata.gz: bf06db90d4000d4a320e1832e1d02700d3c6d6ce302a1a47699dd5744a03aa07d3635389b56f4890ffb74e715842d0d4623143dc36ed01aceb5614a19e845723
7
- data.tar.gz: ca8701c99fb083ff76ae8aad14cfd0e94f36f9e414e5a6fd570755dfe0e4feab816eeaf2ff98817f45db1e2a4ba14d8c60aa9ff756ccebf473ce2ebffea19d62
6
+ metadata.gz: 7a6948ad99b05f1f9742c1a79391ea3a8f7138420efaa6b6f4b966b86d3460f74e01027311170ba0b051a7ac66e27f7c08998344374bded000cb9ba0d93a5a31
7
+ data.tar.gz: 6515790504ba6e0c848f0c0941de5f3f5fd6f1b9bb396e356af85ea66957f857bfc3865b7b16258d2d5c54fffb55dac5439944884920e4e236766cba3407ff29
@@ -8,7 +8,7 @@ module EhbrsRubyUtils
8
8
  module Parsers
9
9
  class GameInProgress < ::Aranha::Parsers::Html::ItemList
10
10
  ITEMS_XPATH = '//*[@id = "gametables_inprogress_all"]' \
11
- '//*[starts-with(@id, "gametableblock_")]'
11
+ '//*[starts-with(@id, "gametableblock_")]'
12
12
  STATUS_CLASS_PATTERN = /\Agametable_status_(.+)\z/.freeze
13
13
  STATUS_CLASS_PARSER = STATUS_CLASS_PATTERN.to_parser { |m| m[1] }
14
14
 
@@ -29,7 +29,7 @@ module EhbrsRubyUtils
29
29
  private
30
30
 
31
31
  def process_status(status)
32
- status.split(' ').lazy.map { |s| STATUS_CLASS_PARSER.parse(s.strip) }.find(&:present?) ||
32
+ status.split.lazy.map { |s| STATUS_CLASS_PARSER.parse(s.strip) }.find(&:present?) ||
33
33
  raise("No status class found in \"#{status}\"")
34
34
  end
35
35
  end
@@ -9,12 +9,12 @@ module EhbrsRubyUtils
9
9
  module Parsers
10
10
  class Table < ::Aranha::Parsers::Html::Item
11
11
  class Options < ::Aranha::Parsers::Html::ItemList
12
- ITEMS_XPATH = '//div[starts-with(@id, "gameoption_")' \
13
- ' and not(contains(@style, "none"))]'
12
+ ITEMS_XPATH = '//div[starts-with(@id, "gameoption_") ' \
13
+ 'and not(contains(@style, "none"))]'
14
14
 
15
15
  field :label, :string, './div[@class = "row-label"]/text()'
16
16
  field :value, :string, './div[@class = "row-value"]' \
17
- "//*[#{xpath_ends_with('@id', "'_displayed_value'")}]/text()"
17
+ "//*[#{xpath_ends_with('@id', "'_displayed_value'")}]/text()"
18
18
  field :description, :string, './div[@class = "gameoption_description"]/text()'
19
19
 
20
20
  def items_xpath
@@ -7,7 +7,7 @@ module EhbrsRubyUtils
7
7
  class Session < ::SimpleDelegator
8
8
  module SkipTrophies
9
9
  TROPHY_SKIP_BUTTON_XPATH = '//*[@id = "splashedNotifications_overlay"]' \
10
- '//*[starts-with(@id, "continue_btn_")]'
10
+ '//*[starts-with(@id, "continue_btn_")]'
11
11
  TROPHY_SKIP_TIMEOUT = 5
12
12
 
13
13
  # @param &block [Proc]
@@ -18,9 +18,7 @@ module EhbrsRubyUtils
18
18
  end
19
19
 
20
20
  def on_logged(&block)
21
- unless logged?
22
- raise "Login failed for BoardGameUser user \"#{username}\"" unless login
23
- end
21
+ raise "Login failed for BoardGameUser user \"#{username}\"" if !logged? && !login
24
22
 
25
23
  block.call
26
24
  end
@@ -49,7 +49,7 @@ module EhbrsRubyUtils
49
49
  end
50
50
 
51
51
  def title_to_s(title)
52
- '*' + [title_icon, title, title_icon].join(' ') + "*\n\n"
52
+ "*#{[title_icon, title, title_icon].join(' ')}*\n\n"
53
53
  end
54
54
 
55
55
  def players
@@ -26,7 +26,7 @@ module EhbrsRubyUtils
26
26
  end
27
27
 
28
28
  def remaining_fs
29
- ((remaining_f * 1000).round / 10.0).to_s + '%'
29
+ "#{(remaining_f * 1000).round / 10.0}%"
30
30
  end
31
31
 
32
32
  def debugs
@@ -28,7 +28,7 @@ module EhbrsRubyUtils
28
28
 
29
29
  def pop_all
30
30
  r = []
31
- while remaining?; r << pop; end
31
+ r << pop while remaining?
32
32
  r
33
33
  end
34
34
 
@@ -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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module CookingBook
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -7,7 +7,7 @@ module EhbrsRubyUtils
7
7
  module Fs
8
8
  class Selected
9
9
  class Build
10
- DEFAULT_TARGET_BASENAME_PROC = ::Proc.new { |path| path.basename.to_path }
10
+ DEFAULT_TARGET_BASENAME_PROC = proc { |path| path.basename.to_path }
11
11
 
12
12
  attr_reader :selected, :target_dir, :target_basename_proc
13
13
 
@@ -31,7 +31,7 @@ module EhbrsRubyUtils
31
31
  end
32
32
 
33
33
  def link_to_header
34
- "<a href=\"\##{header_id}\" id=\"#{index_id}\">#{header_title}</a>"
34
+ "<a href=\"##{header_id}\" id=\"#{index_id}\">#{header_title}</a>"
35
35
  end
36
36
 
37
37
  def index_id
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'eac_templates/patches/object/template'
4
4
 
5
- ::EacTemplates::Searcher.default.included_paths <<
6
- ::File.expand_path('../../../../template', __dir__)
5
+ EacTemplates::Searcher.default.included_paths <<
6
+ File.expand_path('../../../../template', __dir__)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/require_sub'
4
- ::EacRubyUtils.require_sub __FILE__
4
+ EacRubyUtils.require_sub __FILE__
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/require_sub'
4
- ::EacRubyUtils.require_sub __FILE__
4
+ EacRubyUtils.require_sub __FILE__
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.32.0'
4
+ VERSION = '0.35.0'
5
5
  end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs/executables'
5
+ require 'ehbrs_ruby_utils/vg/wii/wit/image_format'
6
+ require 'ehbrs_ruby_utils/vg/wii/wit/path'
7
+ require 'fileutils'
8
+
9
+ module EhbrsRubyUtils
10
+ module Vg
11
+ module Wii
12
+ class FileMove
13
+ common_constructor :game, :target do
14
+ self.target = ::EhbrsRubyUtils::Vg::Wii::Wit::Path.assert(target)
15
+ end
16
+
17
+ ['', 'path_', 'type_'].each do |prefix|
18
+ method_name = "#{prefix}change?"
19
+ define_method(method_name) do
20
+ source.send(method_name, target)
21
+ end
22
+ end
23
+
24
+ def run
25
+ [%w[path type], %w[path], %w[type]].each do |parts|
26
+ next unless parts.all? { |part| send("#{part}_change?") }
27
+
28
+ assert_target_dir
29
+ send("change_#{parts.join('_and_')}")
30
+ check_target
31
+ break
32
+ end
33
+ end
34
+
35
+ def source
36
+ game.wit_path
37
+ end
38
+
39
+ private
40
+
41
+ def assert_target_dir
42
+ target.path.parent.mkpath
43
+ end
44
+
45
+ def change_path
46
+ ::FileUtils.mv(source.path, target.path)
47
+ end
48
+
49
+ def change_path_and_type
50
+ ::Ehbrs::Executables.wit.command
51
+ .append(change_path_and_type_args)
52
+ .system!
53
+ check_target
54
+ source.path.unlink
55
+ end
56
+
57
+ def change_path_and_type_args
58
+ r = %w[copy]
59
+ target_image_format.if_present { |v| r << v.option }
60
+ r + [source.path, target.path]
61
+ end
62
+
63
+ def change_type
64
+ ::Ehbrs::Executables.wit.command
65
+ .append(change_type_args)
66
+ .system!
67
+ end
68
+
69
+ def change_type_args
70
+ r = %w[convert]
71
+ target_image_format.if_present { |v| r << v.option }
72
+ r + [target.path]
73
+ end
74
+
75
+ def check_target
76
+ return if ::EhbrsRubyUtils::Vg::Wii::GameFile.new(target.path).valid?
77
+
78
+ raise "Target \"#{target}\" is not a valid Wii game"
79
+ end
80
+
81
+ def target_image_format
82
+ return nil if target.type.blank?
83
+
84
+ ::EhbrsRubyUtils::Vg::Wii::Wit::ImageFormat.by_name(target.type)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/custom_format'
5
+ require 'ehbrs_ruby_utils/vg/wii/wit/parsers/dump'
6
+ require 'ehbrs_ruby_utils/vg/wii/wit/path'
7
+ require 'pathname'
8
+
9
+ module EhbrsRubyUtils
10
+ module Vg
11
+ module Wii
12
+ class GameFile < ::Pathname
13
+ enable_simple_cache
14
+
15
+ DISC_NUMBER_PATTERN = /disc.?(\d)/i.freeze
16
+
17
+ FORMAT = ::EacRubyUtils::CustomFormat.new(
18
+ b: :basename,
19
+ d: :dirname,
20
+ D: :disc_number,
21
+ e: :extname,
22
+ i: :id6,
23
+ m: :normalized_disc_name,
24
+ n: :disc_name,
25
+ N: :nintendont_basename,
26
+ s: :sanitized_disc_name,
27
+ t: :database_title,
28
+ T: :disc_type
29
+ )
30
+
31
+ def database_title
32
+ properties.fetch('DB title')
33
+ end
34
+
35
+ def disc_name
36
+ properties.fetch('Disc name')
37
+ end
38
+
39
+ def disc_number
40
+ DISC_NUMBER_PATTERN.if_match(basename.to_s, false) { |m| m[1].to_i }.if_present(1)
41
+ end
42
+
43
+ def disc_type
44
+ properties.fetch('File & disc type/type')
45
+ end
46
+
47
+ def format(string)
48
+ FORMAT.format(string).with(self)
49
+ end
50
+
51
+ def normalized_disc_name
52
+ sanitized_disc_name.downcase
53
+ end
54
+
55
+ def nintendont_basename
56
+ n = disc_number
57
+ n == 1 ? 'game' : "disc#{n}"
58
+ end
59
+
60
+ def id6
61
+ properties.fetch('Disc & part IDs/disc')
62
+ end
63
+
64
+ def sanitized_disc_name
65
+ ::ActiveSupport::Inflector.transliterate(disc_name).gsub(/[^0-9a-z ]/i, '')
66
+ end
67
+
68
+ def valid?
69
+ properties.present?
70
+ end
71
+
72
+ def wit_path
73
+ ::EhbrsRubyUtils::Vg::Wii::Wit::Path.new(disc_type, self)
74
+ end
75
+
76
+ private
77
+
78
+ def properties_uncached
79
+ r = ::Ehbrs::Executables.wit.command.append(['dump', to_s]).execute
80
+ return nil unless r.fetch(:exit_code).zero?
81
+
82
+ ::EhbrsRubyUtils::Vg::Wii::Wit::Parsers::Dump.new(r.fetch(:stdout)).properties
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end