#! /bin/usr/env ruby

require File.join(File.dirname(__FILE__), 'HelloWorldFizzBuzz/trollop.rb')
require File.join(File.dirname(__FILE__), 'HelloWorldFizzBuzz/version.rb')
require File.join(File.dirname(__FILE__), 'HelloWorldFizzBuzz/sqlite.rb')
require 'sequel'

# HelloWorldFizzBuzz
module HelloWorldFizzBuzz
  # Program
  class Program
    include HelloWorldFizzBuzz::Sqlite

    def initialize
      connect_database
      startmenu
      options
    end

    def startmenu
      @opts = Trollop.options do
        opt :helloworld, 'creates a helloworld example', short: 'w',
                                                         type: :string
        opt :fizzbuzz, 'creates a fizzbuzz example', short: 'b',
                                                     type: :string
        opt :license, 'show license of HelloWorldFizzBuzz'
      end
    end

    def options
      if @opts[:helloworld]
        hello_world
      elsif @opts[:fizzbuzz]
        fizz_buzz
      elsif @opts[:license]
        license
      end
    end

    def hello_world(hw = @opts[:helloworld].to_s)
      select_language = @posts.where[language: hw]
      if select_language.nil?
        print 'Unknown programming language please try again
'
      elsif puts select_language.fetch(:helloworld)
      end
    end

    def fizz_buzz(fb = @opts[:fizzbuzz].to_s)
      select_language = @posts.where[language: fb]
      if select_language.nil?
        print 'Unknown programming language please try again
'
      elsif puts select_language.fetch(:fizzbuzz)
      end
    end

    def license
      print 'MIT License

Copyright (c) 2016 Derek Viera

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
'
    end
  end
  Program.new
end
