Class: Madweblibs::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/madweblibs/generator.rb

Constant Summary collapse

ADVERBS =
%w{
  awesomely
  fully
  highly
  incredibly
  readily
  semantically
  syntactically
  wonderfully
}
ADJECTIVES =
%w{
  accessible
  asynchronous
  awesome
  beautiful
  consistent
  customizable
  dead-simple
  distributed
  DRY
  durable
  dynamic
  eager-loading
  encrypted
  flexible
  free-as-in-beer
  free-as-in-speech
  full-stack
  functional
  highly-optimized
  lazy-loading
  little
  localized
  modular
  object-oriented
  parallel
  scalable
  schemaless
  semantic
  social
  static
  test-driven
  turing-complete
  type-safe
  unfancy
  web-scale
}
DATABASES =
%w{
  bigtable
  cassandra
  cloud
  couch-db
  memory
  mongo
  postgres
  redis
  yaml
}
NOUNS1 =
[
  'canvas',
  'css',
  'fibers',
  'factories',
  'fixtures',
  'HTML5',
  'javascript',
  'key-value store',
  'message queue',
  'web-socket',
  'web font'
]
NOUNS2 =
[
  'adapter',
  'client',
  'cms',
  'crm',
  'dsl',
  'extension',
  'framework',
  'generator',
  'interface',
  'middleware',
  'orm',
  'parser',
  'plugin',
  'pre-compiler',
  'replacement',
  'state machine',
  'toolkit',
  'wrapper'
]
PLATFORMS =
{
  ActiveRecord: 'active',
  capistrano: 'cap',
  clojure: 'cloj',
  Django: 'jang',
  emacs: 'macs',
  Erlang: 'erl',
  gopher: 'goph',
  groovy: 'groo',
  hadoop: 'doop',
  haskell: 'hask',
  javascript: 'java',
  json: 'jas',
  lua: 'lu',
  NodeJs: 'node',
  python: 'py',
  rails: 'rail',
  ruby: 'ru',
  rvm: 'rev',
  sass: 'sassy',
  scala: 'scal',
  sinatra: 'sin',
  TextMate2: 'mate',
  vim: 'vim'
}

Instance Method Summary collapse

Constructor Details

#initialize(adjective_count, adverb_probability) ⇒ Generator

Returns a new instance of Generator.



7
8
9
10
# File 'lib/madweblibs/generator.rb', line 7

def initialize(adjective_count, adverb_probability)
  @adjective_count = adjective_count
  @adverb_probability = adverb_probability
end

Instance Method Details

#adjective_clauseObject



63
64
65
# File 'lib/madweblibs/generator.rb', line 63

def adjective_clause
  @adjectives.join(', ')
end

#as_a_service_clauseObject



72
73
74
# File 'lib/madweblibs/generator.rb', line 72

def as_a_service_clause
  ["-as-a-service", "", "", ""].sample
end

#generateObject



12
13
14
15
16
17
# File 'lib/madweblibs/generator.rb', line 12

def generate
  get_random_components
  shortname = generate_shortname
  description = generate_description
  "#{shortname}: #{description}"
end

#generate_descriptionObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/madweblibs/generator.rb', line 52

def generate_description
  article = %w{a the}.sample
  desc = "#{adjective_clause} #{storage_clause} #{noun_clause}#{as_a_service_clause} #{platform_clause}."
  if article == 'a'
    first_adjective = desc.split(',').first
    desc.sub!(first_adjective, first_adjective.en.a)
  else
    desc = "#{article} #{desc}"
  end
  desc
end

#generate_shortnameObject



35
36
37
38
39
# File 'lib/madweblibs/generator.rb', line 35

def generate_shortname
  [@database, @platform, @noun1].map do |string|
    shortname_component string
  end.join("") + shortname_suffix
end

#get_random_componentsObject



18
19
20
21
22
23
24
25
26
# File 'lib/madweblibs/generator.rb', line 18

def get_random_components
  @adjectives = ADJECTIVES.sample(@adjective_count).map do |adjective|
    rand < @adverb_probability ? "#{ADVERBS.sample}-#{adjective}" : adjective
  end
  @database = DATABASES.sample
  @noun1 = NOUNS1.sample
  @noun2 = NOUNS2.sample
  @platform = PLATFORMS.keys.sample
end

#noun_clauseObject



69
70
71
# File 'lib/madweblibs/generator.rb', line 69

def noun_clause
  "#{@noun1} #{@noun2}"
end

#platform_clauseObject



75
76
77
# File 'lib/madweblibs/generator.rb', line 75

def platform_clause
  "for #{@platform}"
end

#shortname_component(string) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/madweblibs/generator.rb', line 27

def shortname_component(string)
  component = if PLATFORMS.key? string.to_sym
    PLATFORMS[string.to_sym]
  else
    string[0..2]
  end
  component.capitalize
end

#shortname_suffixObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/madweblibs/generator.rb', line 40

def shortname_suffix
  %w{
    _fu
    gasm
    ie
    ify
    ist
    ize
    tastic
    ly
  }.sample
end

#storage_clauseObject



66
67
68
# File 'lib/madweblibs/generator.rb', line 66

def storage_clause
  "#{@database}-backed"
end