organo 0.3.3 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/organo/commands/anime/anime_add.rb +13 -10
  3. data/lib/organo/commands/anime/anime_add_sequel.rb +25 -16
  4. data/lib/organo/commands/anime/anime_get_broken_links.rb +3 -1
  5. data/lib/organo/commands/anime/anime_remove.rb +4 -0
  6. data/lib/organo/commands/anime/anime_search.rb +4 -7
  7. data/lib/organo/commands/anime/anime_show.rb +4 -0
  8. data/lib/organo/commands/anime/anime_update_image.rb +6 -2
  9. data/lib/organo/commands/anime/anime_update_query.rb +6 -2
  10. data/lib/organo/commands/api/api_get_anime.rb +2 -0
  11. data/lib/organo/commands/api/api_get_season.rb +3 -3
  12. data/lib/organo/commands/api/api_get_sequels.rb +4 -2
  13. data/lib/organo/commands/api/api_search_anime.rb +6 -4
  14. data/lib/organo/commands/init.rb +3 -1
  15. data/lib/organo/commands/merge.rb +7 -3
  16. data/lib/organo/commands/remote/remote_add.rb +10 -6
  17. data/lib/organo/commands/remote/remote_download.rb +7 -3
  18. data/lib/organo/commands/remote/remote_remove.rb +8 -4
  19. data/lib/organo/commands/remote/remote_upload.rb +7 -3
  20. data/lib/organo/commands/statistics.rb +17 -6
  21. data/lib/organo/commands/version.rb +3 -1
  22. data/lib/organo/query.rb +1 -1
  23. data/lib/organo/show_list.rb +2 -2
  24. data/lib/organo/tools/check.rb +12 -0
  25. data/lib/organo/tools/local_search.rb +49 -0
  26. data/lib/organo/{reader.rb → tools/reader.rb} +2 -2
  27. data/lib/organo/version.rb +1 -1
  28. data/lib/organo.rb +27 -32
  29. metadata +9 -7
  30. /data/lib/organo/{search_show.rb → model/search_show.rb} +0 -0
  31. /data/lib/organo/{sequel.rb → model/sequel.rb} +0 -0
  32. /data/lib/organo/{show.rb → model/show.rb} +0 -0
  33. /data/lib/organo/{writer.rb → tools/writer.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16bba44699065f0d0afb4bd22c4c877243dbeeb11c5d3568d146a957f00cfb69
4
- data.tar.gz: 4825637f9a142536d395f859d2309f5741f5fba336ad48eed68822c1c336f29e
3
+ metadata.gz: b58779cd5ac92ef4f14f3b3abd75b221393b45d18f8268e3c967fce213d1563c
4
+ data.tar.gz: b16f8fe0a6b7a2a6cddfd5b49484710923aca86bd21bd6dc034143d352391652
5
5
  SHA512:
6
- metadata.gz: 6144b9c1d789c2618a18e1dcf2ce9eac84c25d5e534fdc3d444102db216657cb4bee82186170bee45f6b5346dd6d0ac0ed6a9781b3137947cd61d1eed3f2a66d
7
- data.tar.gz: f3fc2a18ceb87932457bb11de19cdf3a88f15fa6a1b1665e5a19dbc8bc92459387e9fd293fa985efeabbb78909c40a4754a707c34519c4c889f40499aad2a023
6
+ metadata.gz: ebe9ecb20f6aca8e4248b518a132789296c81b166a263124010d401e6bc9916577c1c9d1224eab9f0610314d634cac78482bd4cc5d474b98de8388e6ce44048e
7
+ data.tar.gz: 2bc797f151ee354347375d77e85f1b7ac0429ed7173a7fa1d2bbce12f4dcb01a339513851059895b251d554d5a4405b91b3995e4703e9e2ceebb3353d46702f3
@@ -1,6 +1,8 @@
1
1
  require_relative '../../config'
2
- require_relative '../../writer'
3
- require_relative '../../reader'
2
+ require_relative '../../tools/writer'
3
+ require_relative '../../tools/reader'
4
+ require_relative '../../tools/local_search'
5
+ require_relative '../../tools/check'
4
6
 
5
7
  module Organo
6
8
  module CLI
@@ -13,15 +15,16 @@ module Organo
13
15
  argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
14
16
 
15
17
  def call(mal_id:, **)
16
- json_obj = Query.get_anime_by_id(mal_id)
17
- show = SearchShow.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'])
18
- show_type = json_obj['type']
19
- file_name = (show_type == 'TV' ? "#{json_obj['year']}_#{json_obj['season']}" : show_type.downcase)
20
- file_path = "#{Config::DEFAULT_DIR}/#{file_name}.json"
21
- show_list = File.exist?(file_path) ? Reader.read_file(file_path) : []
22
- if show_list.find_index { |s| s.id.to_s == mal_id.to_s }.nil?
18
+ Check.init?
19
+ if LocalSearch.find_anime_by_id(mal_id).nil?
20
+ json_obj = Query.get_anime_by_id(mal_id)
21
+ show = SearchShow.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'])
22
+ show_type = json_obj['type']
23
+ file_name = (show_type == 'TV' ? "#{json_obj['year']}_#{json_obj['season']}" : show_type.downcase)
24
+ file_path = "#{Config::DEFAULT_DIR}/#{file_name}.json"
25
+ show_list = File.exist?(file_path) ? Reader.read_file(file_path) : []
23
26
  Writer.to_file(show_list.push(show).sort_by(&:title), file_path)
24
- puts "Added anime \"#{show.title}\" (#{mal_id})"
27
+ puts "Added anime \"#{show.title}\" (#{mal_id}) in #{file_path}"
25
28
  else
26
29
  puts 'Cannot add an already existing anime'
27
30
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../config'
2
- require_relative '../../writer'
3
- require_relative '../../reader'
4
+ require_relative '../../tools/writer'
5
+ require_relative '../../tools/reader'
6
+ require_relative '../../tools/local_search'
7
+ require_relative '../../tools/check'
4
8
 
5
9
  module Organo
6
10
  module CLI
@@ -17,21 +21,26 @@ module Organo
17
21
  argument :type_num, type: :integer, required: false, default: 0, desc: 'The sequel type number'
18
22
 
19
23
  def call(anime_mal_id:, sequel_mal_id:, season_num:, type:, type_num:, **)
20
- json_obj = Query.get_anime_by_id(sequel_mal_id)
21
- Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
22
- shows_list = Reader.read_file(file_path)
23
- show = shows_list.find { |s| s.id.to_s == anime_mal_id.to_s }
24
- next if show.nil?
25
-
26
- if show.sequels.find { |s| s['id'].to_s == sequel_mal_id.to_s }
27
- puts 'Cannot add an already existing sequel.'
28
- else
29
- sequel = Sequel.new(json_obj['mal_id'], json_obj['title'], json_obj['images']['jpg']['image_url'], season_num, type, type_num)
30
- show.sequels.push(sequel)
31
- Writer.to_file(shows_list, file_path)
32
- puts "Added sequel \"#{sequel.title}\" (#{sequel.id}) to anime."
24
+ Check.init?
25
+ if LocalSearch.find_anime_by_id(sequel_mal_id).nil?
26
+ json_obj = Query.get_anime_by_id(sequel_mal_id)
27
+ sequel = Sequel.new(
28
+ json_obj['mal_id'],
29
+ json_obj['title'],
30
+ json_obj['images']['jpg']['image_url'],
31
+ season_num,
32
+ type,
33
+ type_num
34
+ )
35
+ file_path = LocalSearch.find_file_by_anime_id(anime_mal_id)
36
+ show_list = Reader.read_file(file_path).each do |show|
37
+ show.sequels.push(sequel) if show.id == anime_mal_id.to_i
33
38
  end
34
- break
39
+ show_info = show_list.find { |show| show.id == anime_mal_id.to_i }
40
+ Writer.to_file(show_list, file_path)
41
+ puts "Added sequel \"#{sequel.title}\" (#{sequel.id}) to anime \"#{show_info.title}\" (#{anime_mal_id}) in #{file_path}."
42
+ else
43
+ puts 'This sequel already exists.'
35
44
  end
36
45
  end
37
46
  end
@@ -1,5 +1,6 @@
1
1
  require 'httparty'
2
- require_relative '../../reader'
2
+ require_relative '../../tools/reader'
3
+ require_relative '../../tools/check'
3
4
 
4
5
  module Organo
5
6
  module CLI
@@ -11,6 +12,7 @@ module Organo
11
12
  desc 'Get list of anime IDs that have broken links'
12
13
 
13
14
  def call(*)
15
+ Check.init?
14
16
  show_list = Reader.read_all_files
15
17
  broken_list = []
16
18
  show_list.each do |show|
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../config'
4
+ require_relative '../../tools/check'
2
5
 
3
6
  module Organo
4
7
  module CLI
@@ -10,6 +13,7 @@ module Organo
10
13
  argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
11
14
 
12
15
  def call(mal_id:, **)
16
+ Check.init?
13
17
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
14
18
  shows_list = Reader.read_file(file_path)
15
19
  show_index = shows_list.find_index { |s| s.id.to_s == mal_id.to_s }
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../../config'
4
+ require_relative '../../tools/local_search'
5
+ require_relative '../../tools/check'
4
6
 
5
7
  module Organo
6
8
  module CLI
@@ -12,13 +14,8 @@ module Organo
12
14
  argument :query, type: :string, required: true, desc: 'Search query'
13
15
 
14
16
  def call(query:, **)
15
- found_list = []
16
- Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
17
- shows_list = Reader.read_file(file_path)
18
- show = shows_list.find { |s| s.title.downcase.include? query }
19
- found_list.push(show) unless show.nil?
20
- end
21
- puts found_list.to_json
17
+ Check.init?
18
+ puts (LocalSearch.find_anime_by_query(query).map{ |anime| anime.to_json} )
22
19
  end
23
20
  end
24
21
 
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../config'
4
+ require_relative '../../tools/check'
2
5
 
3
6
  module Organo
4
7
  module CLI
@@ -10,6 +13,7 @@ module Organo
10
13
  argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
11
14
 
12
15
  def call(mal_id:, **)
16
+ Check.init?
13
17
  found = false
14
18
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
15
19
  shows_list = Reader.read_file(file_path)
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../config'
2
4
  require_relative '../../query'
3
- require_relative '../../writer'
4
- require_relative '../../reader'
5
+ require_relative '../../tools/writer'
6
+ require_relative '../../tools/reader'
7
+ require_relative '../../tools/check'
5
8
 
6
9
  module Organo
7
10
  module CLI
@@ -14,6 +17,7 @@ module Organo
14
17
  argument :mal_id_list, type: :array, required: true, desc: 'MyAnimeList ID list'
15
18
 
16
19
  def call(mal_id_list:, **)
20
+ Check.init?
17
21
  found = false
18
22
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
19
23
  shows_list = Reader.read_file(file_path)
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../config'
2
- require_relative '../../writer'
3
- require_relative '../../reader'
4
+ require_relative '../../tools/writer'
5
+ require_relative '../../tools/reader'
6
+ require_relative '../../tools/check'
4
7
 
5
8
  module Organo
6
9
  module CLI
@@ -14,6 +17,7 @@ module Organo
14
17
  argument :search_query, type: :string, required: true, desc: 'String query for Nyaa Torrents search'
15
18
 
16
19
  def call(mal_id:, search_query:, **)
20
+ Check.init?
17
21
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
18
22
  shows_list = Reader.read_file(file_path)
19
23
  show = shows_list.find { |s| s.id.to_s == mal_id.to_s }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../query'
2
4
  require_relative '../../show_list'
3
5
 
@@ -8,9 +8,9 @@ module Organo
8
8
  module Get
9
9
 
10
10
  class Season < Dry::CLI::Command
11
- desc "Get list of anime for a specific season"
12
- argument :season, type: :string, required: true, desc: "Winter, Spring, Summer or Fall"
13
- argument :year, type: :integer, required: true, desc: "Year"
11
+ desc 'Get list of anime for a specific season'
12
+ argument :season, type: :string, required: true, desc: 'Winter, Spring, Summer or Fall'
13
+ argument :year, type: :integer, required: true, desc: 'Year'
14
14
 
15
15
  def call(season:, year:, **)
16
16
  json_obj = Query.get_anime_season(season, year)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../query'
2
4
  require_relative '../../show_list'
3
5
 
@@ -8,8 +10,8 @@ module Organo
8
10
  module Get
9
11
 
10
12
  class Sequels < Dry::CLI::Command
11
- desc "Get list of sequels for a specific anime"
12
- argument :mal_id, type: :integer, required: true, desc: "MyAnimeList ID"
13
+ desc 'Get list of sequels for a specific anime'
14
+ argument :mal_id, type: :integer, required: true, desc: 'MyAnimeList ID'
13
15
 
14
16
  def call(mal_id:, **)
15
17
  sequels = ShowList.create_search_sequel_list(Query.get_anime_sequel(mal_id))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../query'
2
4
  require_relative '../../show_list'
3
5
 
@@ -8,10 +10,10 @@ module Organo
8
10
  module Search
9
11
 
10
12
  class Anime < Dry::CLI::Command
11
- desc "Get a list anime from query"
12
- argument :query, type: :string, required: true, desc: "Search query"
13
- option :type, type: :string, required: false, default: '', values: %w[tv movie ova special ona music], desc: "Type of anime"
14
- option :limit, type: :integer, required: false, default: 5, desc: "Limit number of results"
13
+ desc 'Get a list anime from query'
14
+ argument :query, type: :string, required: true, desc: 'Search query'
15
+ option :type, type: :string, required: false, default: '', values: %w[tv movie ova special ona music], desc: 'Type of anime'
16
+ option :limit, type: :integer, required: false, default: 5, desc: 'Limit number of results'
15
17
 
16
18
  def call(query:, type:, limit:, **)
17
19
  json_obj = Query.search_anime(query, { 'type' => type, 'limit' => limit})
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Organo
2
4
  module CLI
3
5
  module Commands
4
6
 
5
7
  class Init < Dry::CLI::Command
6
- desc "Initialize directory with default files and directories"
8
+ desc 'Initialize directory with default files and directories'
7
9
 
8
10
  def call(*)
9
11
  Dir.mkdir './.organo' unless File.exist?('./.organo')
@@ -1,14 +1,18 @@
1
- require_relative '../reader'
2
- require_relative '../writer'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../tools/reader'
4
+ require_relative '../tools/writer'
5
+ require_relative '../tools/check'
3
6
 
4
7
  module Organo
5
8
  module CLI
6
9
  module Commands
7
10
 
8
11
  class Merge < Dry::CLI::Command
9
- desc "Merge edited seasonal files into one main file"
12
+ desc 'Merge edited seasonal files into one main file'
10
13
 
11
14
  def call(*)
15
+ Check.init?
12
16
  show_list = Reader.read_all_files
13
17
  Writer.to_data_file(show_list, 'shows')
14
18
  puts 'Edited files have been merged.'
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../config'
4
+ require_relative '../../tools/check'
2
5
 
3
6
  module Organo
4
7
  module CLI
@@ -6,14 +9,15 @@ module Organo
6
9
  module Remote
7
10
 
8
11
  class Add < Dry::CLI::Command
9
- desc "Add remote FTP server to config file"
10
- argument :env, type: :string, required: true, desc: "Remote environment name"
11
- argument :url, type: :string, required: true, desc: "FTP server url"
12
- option :username, type: :string, default: '', desc: "FTP account username"
13
- option :password, type: :string, default: '', desc: "FTP account password"
14
- option :directory, type: :string, default: '', desc: "FTP directory"
12
+ desc 'Add remote FTP server to config file'
13
+ argument :env, type: :string, required: true, desc: 'Remote environment name'
14
+ argument :url, type: :string, required: true, desc: 'FTP server url'
15
+ option :username, type: :string, default: '', desc: 'FTP account username'
16
+ option :password, type: :string, default: '', desc: 'FTP account password'
17
+ option :directory, type: :string, default: '', desc: 'FTP directory'
15
18
 
16
19
  def call(env:, url:, username:, password:, directory:, **)
20
+ Check.init?
17
21
  config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : Array.new
18
22
  section = config.find { |option| option['section'] == 'remotes' }
19
23
  remote = { env: env, url: url, username: username, password: password, directory: directory }
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/ftp'
4
+ require_relative '../../tools/check'
2
5
 
3
6
  module Organo
4
7
  module CLI
@@ -6,14 +9,15 @@ module Organo
6
9
  module Remote
7
10
 
8
11
  class Download < Dry::CLI::Command
9
- desc "Download data from website"
10
- argument :env, type: :string, required: true, desc: "Environment"
12
+ desc 'Download data from website'
13
+ argument :env, type: :string, required: true, desc: 'Environment'
11
14
 
12
15
  def call(env:, **)
16
+ Check.init?
13
17
  config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : nil
14
18
  section = config.find { |option| option['section'] == 'remotes' }
15
19
  if section.nil?
16
- puts "No remote is configured in the configuration file"
20
+ puts 'No remote is configured in the configuration file'
17
21
  else
18
22
  credentials = section['entries'].find { |entry| entry['env'] == env }
19
23
  if credentials.nil?
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../config'
4
+ require_relative '../../tools/check'
2
5
 
3
6
  module Organo
4
7
  module CLI
@@ -6,17 +9,18 @@ module Organo
6
9
  module Remote
7
10
 
8
11
  class Remove < Dry::CLI::Command
9
- desc "Remove remote FTP server from config file"
10
- argument :env, type: :string, required: true, desc: "Remote environment name"
12
+ desc 'Remove remote FTP server from config file'
13
+ argument :env, type: :string, required: true, desc: 'Remote environment name'
11
14
 
12
15
  def call(env:, **)
16
+ Check.init?
13
17
  config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : nil
14
18
  unless config.nil?
15
19
  section = config.find { |option| option['section'] == 'remotes' }
16
- unless section.nil?
20
+ if !section.nil?
17
21
  index = section['entries'].find_index { |entry| entry['env'] == env }
18
22
  if index.nil?
19
- puts "Specified environment does not exist"
23
+ puts 'Specified environment does not exist'
20
24
  elsif !section['entries'].delete_at(index).nil?
21
25
  puts "Removed \"#{env}\" entry"
22
26
  end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/ftp'
4
+ require_relative '../../tools/check'
2
5
 
3
6
  module Organo
4
7
  module CLI
@@ -6,14 +9,15 @@ module Organo
6
9
  module Remote
7
10
 
8
11
  class Upload < Dry::CLI::Command
9
- desc "Upload data to the website FTP"
10
- argument :env, type: :string, required: true, desc: "Environment"
12
+ desc 'Upload data to the website FTP'
13
+ argument :env, type: :string, required: true, desc: 'Environment'
11
14
 
12
15
  def call(env:, **)
16
+ Check.init?
13
17
  config = File.exist?(Config::DEFAULT_FILE) ? JSON.parse(File.read(Config::DEFAULT_FILE)) : nil
14
18
  section = config.find { |option| option['section'] == 'remotes' }
15
19
  if section.nil?
16
- puts "No remote is configured in the configuration file"
20
+ puts 'No remote is configured in the configuration file'
17
21
  else
18
22
  credentials = section['entries'].find { |entry| entry['env'] == env }
19
23
  if credentials.nil?
@@ -1,23 +1,34 @@
1
- require_relative '../reader'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../tools/reader'
4
+ require_relative '../tools/check'
2
5
 
3
6
  module Organo
4
7
  module CLI
5
8
  module Commands
6
9
 
7
10
  class Statistics < Dry::CLI::Command
8
- desc "Merge edited seasonal files into one main file"
11
+ desc 'Merge edited seasonal files into one main file'
9
12
 
10
13
  def call(*)
11
- i = 0
14
+ Check.init?
15
+ shows_num = 0
12
16
  total_size = 0
17
+ sequels_num = 0
13
18
  Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
14
19
  shows = Reader.read_file(file_path)
15
20
  file_size = File.size(file_path)
16
- puts "#{File.basename(file_path)}: #{shows.count} (#{file_size} b)"
17
- i += shows.count
21
+ puts "#{File.basename(file_path)}: #{shows.count} (#{file_size.to_f / 1000} KB)"
22
+ shows_num += shows.count
23
+ shows.each do |show|
24
+ sequels_num += show.sequels.size
25
+ end
18
26
  total_size += file_size
19
27
  end
20
- puts "Total count: #{i} (#{total_size} o)"
28
+ puts '------------------------------'
29
+ puts "Shows count: #{shows_num}"
30
+ puts "Sequels count: #{sequels_num}"
31
+ puts "Total file size: #{total_size.to_f / 1000} KB"
21
32
  end
22
33
  end
23
34
 
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../version'
2
4
 
3
5
  module Organo
4
6
  module CLI
5
7
  module Commands
6
8
  class Version < Dry::CLI::Command
7
- desc "Print version"
9
+ desc 'Print version'
8
10
 
9
11
  def call(*)
10
12
  puts Organo::VERSION
data/lib/organo/query.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative 'jikan_api'
4
4
  require_relative 'request'
5
- require_relative 'search_show'
5
+ require_relative 'model/search_show'
6
6
 
7
7
  module Organo
8
8
  class Query
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
- require_relative 'search_show'
5
- require_relative 'sequel'
4
+ require_relative 'model/search_show'
5
+ require_relative 'model/sequel'
6
6
  require_relative 'query'
7
7
 
8
8
  module Organo
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Organo
4
+ class Check
5
+ def self.init?
6
+ unless Dir.exist?('.organo')
7
+ puts "Directory is not initialized.\nYou can initialize the current directory with the following command:\n$ organo init"
8
+ exit
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require_relative 'reader'
5
+
6
+ module Organo
7
+ class LocalSearch
8
+
9
+ def self.find_anime_by_id(mal_id)
10
+ anime_list = Reader.read_all_files
11
+ get_anime_obj(mal_id, anime_list)
12
+ end
13
+
14
+ def self.get_anime_obj(mal_id, anime_list)
15
+ return_value = nil
16
+ anime_list.each do |anime|
17
+ if anime.id == mal_id.to_i || anime.sequels.find { |sequel| sequel['id'] == mal_id.to_i }
18
+ return_value = anime
19
+ break
20
+ end
21
+ end
22
+ return_value
23
+ end
24
+
25
+ def self.find_file_by_anime_id(mal_id)
26
+ return_value = nil
27
+ Dir["#{Config::DEFAULT_DIR}/*.json"].each do |file_path|
28
+ anime_list = Reader.read_file(file_path)
29
+ unless get_anime_obj(mal_id, anime_list).nil?
30
+ return_value = file_path
31
+ break
32
+ end
33
+ end
34
+ return_value
35
+ end
36
+
37
+ def self.find_anime_by_query(query)
38
+ anime_list = Reader.read_all_files
39
+ return_value = []
40
+ anime_list.each do |anime|
41
+ if (anime.title.downcase.include? query.downcase) ||
42
+ (anime.sequels.find { |sequel| sequel['title'].downcase.include? query.downcase })
43
+ return_value.push(anime)
44
+ end
45
+ end
46
+ return_value
47
+ end
48
+ end
49
+ end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
- require_relative 'config'
5
- require_relative 'show'
4
+ require_relative '../config'
5
+ require_relative '../model/show'
6
6
 
7
7
  module Organo
8
8
  class Reader
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Organo
4
- VERSION = '0.3.3'
4
+ VERSION = '0.3.5'
5
5
  end
data/lib/organo.rb CHANGED
@@ -30,38 +30,33 @@ module Organo
30
30
 
31
31
  register 'version', Version, aliases: %w[v -v --version]
32
32
  register 'init', Init
33
-
34
- if Dir.exist?('.organo')
35
- register 'anime' do |prefix|
36
- prefix.register 'add', Anime::Add::AnimeEntry
37
- prefix.register 'add sequel', Anime::Add::SequelEntry
38
- prefix.register 'remove', Anime::Remove
39
- prefix.register 'show', Anime::Show
40
- prefix.register 'search', Anime::Search
41
- prefix.register 'update image', Anime::Update::Image
42
- prefix.register 'update search_query', Anime::Update::SearchQuery
43
- prefix.register 'get broken_links', Anime::Get::BrokenLinks
44
- end
45
- register 'api' do |prefix|
46
- prefix.register 'get anime', API::Get::Anime
47
- prefix.register 'get season', API::Get::Season
48
- prefix.register 'get sequels', API::Get::Sequels
49
- prefix.register 'search anime', API::Search::Anime
50
- prefix.register 'get schedule', API::Get::Schedule
51
- end
52
- register 'merge', Merge
53
- register 'statistics', Statistics
54
- register 'remote' do |prefix|
55
- prefix.register 'add', Remote::Add
56
- prefix.register 'remove', Remote::Remove
57
- prefix.register 'download', Remote::Download
58
- prefix.register 'upload', Remote::Upload
59
- end
60
- register 'schedule' do |prefix|
61
- prefix.register 'create', Schedule::Create
62
- end
63
- else
64
- puts 'This directory has not been initialized.'
33
+ register 'anime' do |prefix|
34
+ prefix.register 'add', Anime::Add::AnimeEntry
35
+ prefix.register 'add sequel', Anime::Add::SequelEntry
36
+ prefix.register 'remove', Anime::Remove
37
+ prefix.register 'show', Anime::Show
38
+ prefix.register 'search', Anime::Search
39
+ prefix.register 'update image', Anime::Update::Image
40
+ prefix.register 'update search_query', Anime::Update::SearchQuery
41
+ prefix.register 'get broken_links', Anime::Get::BrokenLinks
42
+ end
43
+ register 'api' do |prefix|
44
+ prefix.register 'get anime', API::Get::Anime
45
+ prefix.register 'get season', API::Get::Season
46
+ prefix.register 'get sequels', API::Get::Sequels
47
+ prefix.register 'search anime', API::Search::Anime
48
+ prefix.register 'get schedule', API::Get::Schedule
49
+ end
50
+ register 'merge', Merge
51
+ register 'statistics', Statistics
52
+ register 'remote' do |prefix|
53
+ prefix.register 'add', Remote::Add
54
+ prefix.register 'remove', Remote::Remove
55
+ prefix.register 'download', Remote::Download
56
+ prefix.register 'upload', Remote::Upload
57
+ end
58
+ register 'schedule' do |prefix|
59
+ prefix.register 'create', Schedule::Create
65
60
  end
66
61
  end
67
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: organo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Louis-Philippe Fortin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-11 00:00:00.000000000 Z
11
+ date: 2023-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -110,15 +110,17 @@ files:
110
110
  - lib/organo/commands/version.rb
111
111
  - lib/organo/config.rb
112
112
  - lib/organo/jikan_api.rb
113
+ - lib/organo/model/search_show.rb
114
+ - lib/organo/model/sequel.rb
115
+ - lib/organo/model/show.rb
113
116
  - lib/organo/query.rb
114
- - lib/organo/reader.rb
115
117
  - lib/organo/request.rb
116
- - lib/organo/search_show.rb
117
- - lib/organo/sequel.rb
118
- - lib/organo/show.rb
119
118
  - lib/organo/show_list.rb
119
+ - lib/organo/tools/check.rb
120
+ - lib/organo/tools/local_search.rb
121
+ - lib/organo/tools/reader.rb
122
+ - lib/organo/tools/writer.rb
120
123
  - lib/organo/version.rb
121
- - lib/organo/writer.rb
122
124
  homepage: https://gitlab.com/dkb-weeblets/organo
123
125
  licenses:
124
126
  - MIT
File without changes
File without changes
File without changes