diff --git a/lib/inspec/objects/attribute.rb b/lib/inspec/objects/attribute.rb index 078a4c159..9fbdffd17 100644 --- a/lib/inspec/objects/attribute.rb +++ b/lib/inspec/objects/attribute.rb @@ -21,6 +21,18 @@ module Inspec @opts[:default] end + def title + @opts[:title] + end + + def description + @opts[:description] + end + + def ruby_var_identifier + 'attr_' + @name.downcase.strip.gsub(/\s+/, '-').gsub(/[^\w-]/, '') + end + def to_hash { name: @name, @@ -28,6 +40,15 @@ module Inspec } end + def to_ruby + res = ["#{ruby_var_identifier} = attribute('#{@name}',{"] + res.push " title: '#{title}'," unless title.to_s.empty? + res.push " default: '#{default}'," unless default.to_s.empty? + res.push " description: '#{description}'," unless description.to_s.empty? + res.push '})' + res.join("\n") + end + def to_s "Attribute #{@name} with #{@value}" end