Sha256: 2bcb02f6ebadfb9696f71445c8ea1cd44b614858e69a5d0261a198933883eb70

Contents?: true

Size: 2 KB

Versions: 13

Compression:

Stored size: 2 KB

Contents

module Rubicure
  require "singleton"

  # generic methods
  class Core
    include Singleton
    include Enumerable
    include Rubicure::Concerns::Util

    def method_missing(name, *args)
      unmarked_precure = Rubicure::Series.find(:unmarked)

      if Rubicure::Series.valid?(name)
        Rubicure::Series.find(name)
      elsif unmarked_precure.respond_to?(name)
        unmarked_precure.send(name, *args)
      else
        super
      end
    end

    # @return [Series] current precure
    # @raise not onair!
    def now
      current_time = Time.now
      each_with_series do |series|
        return series if series.on_air?(current_time)
      end
      raise NotOnAirError, "Not on air precure!"
    end

    alias_method :current, :now

    # @param [Time,Date,String,Symbol] arg Time, Date or date like String (ex. "2013-12-16")
    # @return [Array<Rubicure::Girl>]
    def all_stars(arg = Time.current)
      unless @all_stars
        @all_stars = []
        Rubicure::Girl.names.each do |girl_name|
          @all_stars << Rubicure::Girl.find(girl_name)
        end

        @all_stars.uniq!(&:human_name)
      end

      extra_girls = []

      # args is Time or Date
      date = to_date(arg)

      unless date
        # args is movie name
        movie = Rubicure::Movie.find(arg.to_sym)
        date = movie.started_date

        if movie.has_key?(:extra_girls)
          extra_girls = movie.extra_girls.map { |girl_name| Rubicure::Girl.find(girl_name.to_sym) }
        end
      end

      girls = @all_stars.select { |girl| girl.created_date && girl.created_date <= date }
      girls + extra_girls
    end

    # iterate with :unmarked, :max_heart, ...
    #
    # @yield series
    # @yieldparam series [Rubicure::Series]
    #
    # @return [Array<Symbol>] ex. :unmarked, :max_heart, ...
    def each_with_series
      Rubicure::Series.uniq_names.each do |series_name|
        series = Rubicure::Series.find(series_name)
        yield series
      end
    end

    alias_method :each, :each_with_series
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rubicure-0.4.13 lib/rubicure/core.rb
rubicure-1.0.0.pre2 lib/rubicure/core.rb
rubicure-1.0.0.pre1 lib/rubicure/core.rb
rubicure-0.4.12 lib/rubicure/core.rb
rubicure-0.4.11 lib/rubicure/core.rb
rubicure-0.4.10 lib/rubicure/core.rb
rubicure-0.4.9 lib/rubicure/core.rb
rubicure-0.4.8 lib/rubicure/core.rb
rubicure-0.4.7 lib/rubicure/core.rb
rubicure-0.4.6 lib/rubicure/core.rb
rubicure-0.4.5 lib/rubicure/core.rb
rubicure-0.4.4 lib/rubicure/core.rb
rubicure-0.4.3 lib/rubicure/core.rb