class AVIP

Public Class Methods

new(ip = '127.0.0.1', content = []) click to toggle source
# File lib/av-ip.rb, line 6
def initialize(ip = '127.0.0.1', content = [])
        @ip = ip
        @content = content
        @params = [
                :format,
                :ip,
                :content
        ]

        @contents = [
                :ip,
                :hostname,
                :city,
                :region,
                :country,
                :loc,
                :org,
                :postal
        ]
end

Public Instance Methods

update(param_hash) click to toggle source

Input options in hash form ie {:format => :json, :ip => ‘127.0.0.1’}

# File lib/av-ip.rb, line 28
def update(param_hash)
        param_hash.each do |key,value|
                if @params.include?(key)
                        if key == :ip
                                @ip = value
                                puts "Ip changed to #{value}."
                        elsif key == :content
                                if value.length == 0
                                        puts "Invalid Input, using all outputs"
                                else
                                        content = []
                                        value.each do |val|
                                                if @contents.include?(val)
                                                        @content.push(val)
                                                        puts "Including: #{val}"
                                                else
                                                        puts "#{val} is not a valid option."
                                                end
                                        end
                                end
                        end
                else
                        puts "Paramater: #{key} is not a valid option."
                        puts "Warning: No change has been made."  
                end
        end
end