Class: Rubicure::Series

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

Overview

Precure TV series (ex. Smile Precure, Dokidoki Orecure) this is record of “config/series.yml”

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Util

load_yaml_file, to_date

Class Method Details

.configHash

Returns content of config/series.yml.

Returns:

  • (Hash)

    content of config/series.yml



109
110
111
112
113
114
115
# File 'lib/rubicure/series.rb', line 109

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

.find(series_name) ⇒ Rubicure::Series

Parameters:

  • series_name (Symbol)

Returns:

Raises:

  • arg is not precure



132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/rubicure/series.rb', line 132

def find(series_name)
  raise UnknownSeriesError, "unknown series: #{series_name}" unless valid?(series_name)

  @cache ||= {}
  unless @cache[series_name]
    series_config = config[series_name] || {}
    series_config.compact!

    @cache[series_name] = Rubicure::Series[series_config]
  end

  @cache[series_name]
end

.namesArray<Symbol>

Returns:

  • (Array<Symbol>)


95
96
97
# File 'lib/rubicure/series.rb', line 95

def names
  config.keys
end

.reload_config!Hash

Returns content of config/precure.yml.

Returns:

  • (Hash)

    content of config/precure.yml



118
119
120
121
122
# File 'lib/rubicure/series.rb', line 118

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

.uniq_namesArray<Symbol>

Returns:

  • (Array<Symbol>)


100
101
102
103
104
105
106
# File 'lib/rubicure/series.rb', line 100

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)


125
126
127
# File 'lib/rubicure/series.rb', line 125

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

Instance Method Details

#===(other) ⇒ Boolean

Returns other is same Rubicure::Series or Rubicure::Series include Rubicure::Girl.

Parameters:

Returns:

  • (Boolean)

    other is same Rubicure::Series or Rubicure::Series include Rubicure::Girl



17
18
19
20
21
22
23
24
25
26
# File 'lib/rubicure/series.rb', line 17

def ===(other)
  case other
  when self.class
    self == other
  when Rubicure::Girl
    girls.include? other
  else
    false
  end
end

#each(&block) ⇒ Object



65
66
67
# File 'lib/rubicure/series.rb', line 65

def each(&block)
  girls.each(&block)
end

#each_without_girlsObject



63
# File 'lib/rubicure/series.rb', line 63

alias_method :each_without_girls, :each

#girlsArray<Rubicure::Girl> Also known as: members

Returns:



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

def girls
  unless @girls
    @girls = []
    if has_key?(:girls)
      fetch(:girls).each do |girl_name|
        @girls << Rubicure::Girl.find(girl_name.to_sym)
      end
    end
  end

  @girls
end

#heisei?Boolean

Whether Heisei precure

Returns:

  • (Boolean)


79
80
81
# File 'lib/rubicure/series.rb', line 79

def heisei?
  started_date.heisei? || ended_date.heisei?
end

#on_air?(arg) ⇒ Boolean

Whether series is on air

Parameters:

  • arg (Time, Date, String)

    Time, Date or date like String (ex. “2013-12-16”)

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rubicure/series.rb', line 33

def on_air?(arg)
  date = to_date(arg)

  return false unless respond_to?(:started_date)

  if respond_to?(:ended_date)
    # ended title
    (started_date..ended_date).cover?(date)
  else
    # on air title
    started_date <= date
  end
end

#reiwa?Boolean

Whether Reiwa precure

Returns:

  • (Boolean)


84
85
86
87
88
89
# File 'lib/rubicure/series.rb', line 84

def reiwa?
  # TODO: Remove after StarTwinkle Precure is finished
  return true unless has_key?(:ended_date)

  started_date.reiwa? || ended_date.reiwa?
end

#to_json(*_args) ⇒ String

Returns json string.

Returns:

  • (String)

    json string



70
71
72
73
74
75
76
# File 'lib/rubicure/series.rb', line 70

def to_json(*_args)
  original_hash = {}
  each_without_girls do |k, v|
    original_hash[k] = v
  end
  original_hash.to_json
end