File: movie.rb

package info (click to toggle)
ruby-ffaker 2.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,776 kB
  • sloc: ruby: 12,788; makefile: 8; sh: 1
file content (69 lines) | stat: -rw-r--r-- 2,131 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true

module FFaker
  module Movie
    extend ModuleUtils
    extend self

    SUFFIXES = [
      'from Hell', 'from Outer Space', 'from Mars', 'from the Black Lagoon',
      'with a Thousand Faces', 'from Across the Ocean', 'Who Fell to Earth', 'That Came to Dinner'
    ].freeze
    COLORS = %w[Red Yellow Black White].freeze

    RATINGS = %w[G PG PG-13 R NC-17].freeze # According to MPAA

    def title
      case rand(0..3)
      when 0 then title_with_prefix
      when 1 then title_with_suffix
      when 2 then simple_title
      when 3 then title_from_formula
      end
    end

    def rating
      fetch_sample(RATINGS)
    end

    private

    def title_with_prefix
      "#{fetch_sample(PREFIXES)} #{maybe_adj_or_adv}#{fetch_sample(NOUNS)}"
    end

    def title_with_suffix
      "The #{maybe_adj_or_adv}#{fetch_sample(NOUNS)} #{fetch_sample(SUFFIXES)}"
    end

    def maybe_adj_or_adv
      "#{fetch_sample(ADJ_AND_ADV)} " if rand(0..1) == 1
    end

    def simple_title
      "#{fetch_sample(ADJ_AND_ADV)} #{fetch_sample(NOUNS)}"
    end

    def title_from_formula
      case rand(0..12)
      when 0 then "#{fetch_sample(NOUNS)} 2: Electric Boogaloo"
      when 1 then "The #{fetch_sample(NOUNS)} Without a #{fetch_sample(NOUNS)}"
      when 2 then "The #{fetch_sample(NOUNS)} from #{rand(0...20_000)} Leagues"
      when 3 then "#{simple_title}: The #{FFaker::Name.name} Story"
      when 4 then "When #{FFaker::Name.first_name} Met #{FFaker::Name.first_name}"
      when 5 then "Dr. #{fetch_sample(NOUNS)}"
      when 6 then "Je Vous Presente, #{FFaker::Name.first_name}"
      when 7 then "#{rand(0...2999)} A.D."
      when 8 then "The #{fetch_sample(NOUNS)} from #{FFaker::Address.neighborhood}"
      when 9 then "Christmas on #{FFaker::Address.street_name}"
      when 10 then "The #{fetch_sample(COLORS)} Rose of #{FFaker::AddressUK.country}"
      when 11 then "Hard Boiled #{fetch_sample(NOUNS)}"
      else
        ::String.new.tap do |string|
          title = simple_title
          string.replace("#{title} 2: Son of #{title}")
        end
      end
    end
  end
end