Skip to content

Commit

Permalink
Get helpers test to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
dropofwill committed May 15, 2015
1 parent df33d6e commit 192582a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
5 changes: 3 additions & 2 deletions lib/rtasklib/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module Rtasklib

# Accessed through the main TW, which includes this module, e.g. `tw.all`
#
# Ideally should only be the well documented public, user-facing methods.
# We're getting there.
#
Expand Down Expand Up @@ -148,15 +149,15 @@ def deep_attr attr, depth: 2
private :deep_attr

#
def add_uda_to_model uda_hash, type=nil, model=Models::TaskModel
def add_udas_to_model! uda_hash, type=nil, model=Models::TaskModel
uda_hash.each do |attr, val|
val.each do |k, v|
type = Helpers.determine_type(v) if type.nil?
model.attribute attr, type
end
end
end
private :add_uda_to_model
private :add_udas_to_model!

# Retrieve an array of the uda names
#
Expand Down
6 changes: 5 additions & 1 deletion lib/rtasklib/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ module Helpers
#
# @param raw [String]
# @return [Gem::Version]
# @api public
def to_gem_version raw
std_ver = raw.chomp.gsub(' ','.').delete('(').delete(')')
Gem::Version.new std_ver
end
private :to_gem_version

# Determine the type that a value should be coerced to
# Int needs to precede float because ints are also floats
Expand All @@ -33,6 +33,7 @@ def to_gem_version raw
#
# @param value [Object] anything that needs to be coerced, probably string
# @return [Axiom::Types::Boolean, Integer, Float, String]
# @api public
def determine_type value
if boolean? value
return Axiom::Types::Boolean
Expand All @@ -48,20 +49,23 @@ def determine_type value
# Can the input be coerced to an integer without losing information?
#
# @return [Boolean]
# @api public
def integer? value
value.to_i.to_s == value rescue false
end

# Can the input be coerced to a float without losing information?
#
# @return [Boolean]
# @api public
def float? value
Float(value) rescue false
end

# Can the input be coerced to a boolean without losing information?
#
# @return [Boolean]
# @api public
def boolean? value
["on", "off", "yes", "no", "false", "true"]
.include? value.to_s.downcase rescue false
Expand Down
5 changes: 0 additions & 5 deletions spec/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
describe Rtasklib::Controller do
include Rtasklib::Controller

it 'can handle sub version numbers' do
expect(to_gem_version("2.5.3 (afdj5)"))
.to eq(Gem::Version.new("2.5.3.afdj5"))
end

describe 'Rtasklib::Controller#all' do
end

Expand Down
13 changes: 13 additions & 0 deletions spec/helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'spec_helper'

describe Rtasklib::Helpers do
puts Rtasklib::Helpers

describe 'Rtasklib::Helpers#to_gem_version' do

it 'can handle sub version numbers' do
expect(Rtasklib::Helpers.to_gem_version("2.5.3 (afdj5)"))
.to eq(Gem::Version.new("2.5.3.afdj5"))
end
end
end

0 comments on commit 192582a

Please sign in to comment.