Class: Puppet_X::Coi::Jboss::BuildinsUtils::ToBooleanConverter
- Inherits:
-
Object
- Object
- Puppet_X::Coi::Jboss::BuildinsUtils::ToBooleanConverter
- Defined in:
- lib/puppet_x/coi/jboss/buildins_utils.rb
Overview
Thsi class handles convertion from various types to boolean
Instance Method Summary collapse
-
#initialize(target) ⇒ ToBooleanConverter
constructor
Constructor.
-
#to_bool ⇒ Object
Converts given value to boolean value.
Constructor Details
#initialize(target) ⇒ ToBooleanConverter
Constructor
34 35 36 |
# File 'lib/puppet_x/coi/jboss/buildins_utils.rb', line 34 def initialize(target) @target = target end |
Instance Method Details
#to_bool ⇒ Object
Converts given value to boolean value
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/puppet_x/coi/jboss/buildins_utils.rb', line 38 def to_bool if @target.respond_to?(:empty?) str = @target else str = @target.to_s end if @target.is_a? Numeric return @target != 0 end return true if @target == true || str =~ (/(true|t|yes|y)$/i) bm = BlankMatcher.new(@target) return false if @target == false || bm.blank? || str =~ (/(false|f|no|n)$/i) raise ArgumentError.new("invalid value for Boolean: \"#{@target}\"") end |