Class: Rubicure::Movie

Inherits:
Hash
  • Object
show all
Extended by:
Concerns::Util
Includes:
Hashie::Extensions::MethodAccess
Defined in:
lib/rubicure/movie.rb

Overview

Precure All Stars Movie

this is record of “config/movies.yml”

Class Method Summary collapse

Methods included from Concerns::Util

load_yaml_file, to_date

Class Method Details

.configHash

Returns content of config/movies.yml.

Returns:

  • (Hash)

    content of config/movies.yml



26
27
28
29
30
31
32
# File 'lib/rubicure/movie.rb', line 26

def config
  unless @config
    config_file = "#{File.dirname(__FILE__)}/../../config/movies.yml"
    @config = load_yaml_file(config_file).deep_symbolize_keys
  end
  @config
end

.find(movie_name) ⇒ Rubicure::Movie

Parameters:

  • movie_name (Symbol)

Returns:

Raises:

  • arg is invalid



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rubicure/movie.rb', line 49

def find(movie_name)
  raise UnknownMovieError, "unknown movie: #{movie_name}" unless valid?(movie_name)

  @cache ||= {}
  unless @cache[movie_name]
    movie_config = config[movie_name] || {}
    movie_config.compact!

    @cache[movie_name] = Rubicure::Movie[movie_config]
  end

  @cache[movie_name]
end

.namesArray<Symbol>

Returns:

  • (Array<Symbol>)


12
13
14
# File 'lib/rubicure/movie.rb', line 12

def names
  config.keys
end

.reload_config!Hash

Returns content of config/movies.yml.

Returns:

  • (Hash)

    content of config/movies.yml



35
36
37
38
39
# File 'lib/rubicure/movie.rb', line 35

def reload_config!
  @cache = {}
  @config = nil
  config
end

.uniq_namesArray<Symbol>

Returns:

  • (Array<Symbol>)


17
18
19
20
21
22
23
# File 'lib/rubicure/movie.rb', line 17

def uniq_names
  uniq_names = []
  config.each do |name, series|
    uniq_names << name unless uniq_names.any? {|uniq_name| config[uniq_name][:title] == series[:title] }
  end
  uniq_names
end

.valid?(series_name) ⇒ Boolean

Parameters:

  • series_name (Symbol)

Returns:

  • (Boolean)


42
43
44
# File 'lib/rubicure/movie.rb', line 42

def valid?(series_name)
  names.include?(series_name)
end