Sha256: e1c371afc3a7fe44092bd15c07844f54717bf35306106ccd768525dee01041fd

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

# rubocop:disable all
# frozen_string_literal: true

class ActWithFlags::Admin

  def to_s
    res = []
    res << title('Variables')
    res << variables(:origin, :boolean_hash)
    res << variables(:delete_mask)

    res << title('Flags sorted alfabetically')
    @map.sort.each { |key, pos| res << "#{key}  #{position(key)}" }

    res << title('Flags sorted by position')
    @map.sort.sort_by(&:last).each { |key, pos|
      res << "#{key}  #{position(key)}"
    }

    res << title('Flags and mask; sorted alfabetically')
    @map.sort.each { |key, pos|
      res << "#{key}  #{sprintf('0x%08X', mask(key))}"
    }

    res << title('FLAG assignment; sorted alfabetically')
    @map.sort.each { |key, pos|
      res << "FLAG_#{key.upcase} = #{sprintf('0x%08X', mask(key))}"
    }

    res << title('FLAG assignment; sorted by position')
    @map.sort.sort_by(&:last).each { |key, pos|
      res << "FLAG_#{key.upcase} = #{sprintf('0x%08X', mask(key))}"
    }

    res.flatten.join("\n")
  end

 private
  def title(msg)
    sep = '#' * 10
    ['', "#{sep} #{msg} #{sep}"]
  end

  def variables(*names)
    names.collect { |name|
      value = instance_variable_get(:"@#{name}")
      "#{name} #{value}"
    }
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
act_with_flags-0.2.4 lib/act_with_flags/print.rb
act_with_flags-0.2.3 lib/act_with_flags/print.rb
act_with_flags-0.2.0 lib/act_with_flags/print.rb
act_with_flags-0.1.0 lib/act_with_flags/print.rb
act_with_flags-0.0.7 lib/act_with_flags/print.rb
act_with_flags-0.0.6 lib/act_with_flags/print.rb