Skip to content

Commit

Permalink
chore(doc): document some members
Browse files Browse the repository at this point in the history
  • Loading branch information
randym committed Apr 1, 2017
1 parent b4bdbfa commit 83e2398
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 31 deletions.
4 changes: 3 additions & 1 deletion lib/axlsx/drawing/chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def d_lbls
# Indicates that colors should be varied by datum
# @return [Boolean]
attr_reader :vary_colors

# Configures the vary_colors options for this chart
# @param [Boolean] v The value to set
def vary_colors=(v) Axlsx::validate_boolean(v); @vary_colors = v; end
Expand Down Expand Up @@ -129,6 +129,8 @@ def title=(v)
end

# The size of the Title object of the chart.
# @param [String] v The size for the title object
# @see Title
def title_size=(v)
@title.text_size = v unless v.to_s.empty?
end
Expand Down
2 changes: 0 additions & 2 deletions lib/axlsx/drawing/pic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def relationship
end

# providing access to the anchor's width attribute
# @param [Integer] v
# @see OneCellAnchor.width
def width
return unless @anchor.is_a?(OneCellAnchor)
Expand All @@ -129,7 +128,6 @@ def width=(v)
end

# providing access to update the anchor's height attribute
# @param [Integer] v
# @see OneCellAnchor.width
# @note this is a noop if you are using a TwoCellAnchor
def height
Expand Down
7 changes: 5 additions & 2 deletions lib/axlsx/rels/relationships.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ class Relationships < SimpleTypedList
def initialize
super Relationship
end

# The relationship instance for the given source object, or nil if none exists.
# @see Relationship#source_obj
# @return [Relationship]
def for(source_obj)
find{ |rel| rel.source_obj == source_obj }
end


# serialize relationships
# @param [String] str
# @return [String]
def to_xml_string(str = '')
str << '<?xml version="1.0" encoding="UTF-8"?>'
str << ('<Relationships xmlns="' << RELS_R << '">')
Expand Down
11 changes: 7 additions & 4 deletions lib/axlsx/util/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,16 @@ module Axlsx
# @see http://www.codetable.net/asciikeycodes
pattern = "\x0-\x08\x0B\x0C\x0E-\x1F"
pattern = pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern

# The regular expression used to remove control characters from worksheets
CONTROL_CHARS = pattern.freeze


# ISO 8601 date recognition
ISO_8601_REGEX = /\A(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?\Z/.freeze


# FLOAT recognition
FLOAT_REGEX = /\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/.freeze


# Numeric recognition
NUMERIC_REGEX = /\A[+-]?\d+?\Z/.freeze
end
9 changes: 5 additions & 4 deletions lib/axlsx/util/validators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ def self.validate(name, types, v, other=false)
raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v)
end
v_class = v.is_a?(Class) ? v : v.class
Array(types).each do |t|
Array(types).each do |t|
return if v_class <= t
end
raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect])
end
end


# Requires that the value can be converted to an integer
# @para, [Any] v the value to validate
Expand All @@ -78,7 +78,8 @@ def self.validate_integerish(v)
def self.validate_angle(v)
raise ArgumentError, (ERR_ANGLE % v.inspect) unless (v.to_i >= -5400000 && v.to_i <= 5400000)
end


# Validates an unsigned intger
UINT_VALIDATOR = lambda { |arg| arg.respond_to?(:>=) && arg >= 0 }

# Requires that the value is a Integer and is greater or equal to 0
Expand Down Expand Up @@ -148,7 +149,7 @@ def self.validate_cell_u(v)
RestrictionValidator.validate "cell run style u", [:none, :single, :double, :singleAccounting, :doubleAccounting], v
end

# validates cell style family which must be between 1 and 5
# validates cell style family which must be between 1 and 5
def self.validate_family(v)
RestrictionValidator.validate "cell run style family", 1..5, v
end
Expand Down
4 changes: 4 additions & 0 deletions lib/axlsx/workbook/workbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ def add_worksheet(options={})
worksheet
end

# Adds a new WorkbookView
# @return WorkbookViews
# @option options [Hash] options passed into the added WorkbookView
# @see WorkbookView#initialize
def add_view(options={})
views << WorkbookView.new(options)
end
Expand Down
8 changes: 5 additions & 3 deletions lib/axlsx/workbook/workbook_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class WorkbookView


# Creates a new BookView object
# @params [Hash] options A hash of key/value pairs that will be mapped to this instances attributes.
# @param [Hash] options A hash of key/value pairs that will be mapped to this instances attributes.
# @option [Symbol] visibility Specifies visible state of the workbook window. The default value for this attribute is :visible.
# @option [Boolean] minimized Specifies a boolean value that indicates whether the workbook window is minimized.
# @option [Boolean] show_horizontal_scroll Specifies a boolean value that indicates whether to display the horizontal scroll bar in the user interface.
# @option [Boolean] show_vertical_scroll Specifies a boolean value that indicates whether to display the vertical scroll bar.
# @option [Boolean] show_sheet_tabs Specifies a boolean value that indicates whether to display the sheet tabs in the user interface.
# @option [Integer] tab_ratio Specifies ratio between the workbook tabs bar and the horizontal scroll bar.
# @option [Integer] first_sheet Specifies the index to the first sheet in this book view.
# @option [Integer] active_tab Specifies an unsignedInt that contains the index to the active sheet in this book view.
# @option [Integer] active_tab Specifies an unsignedInt that contains the index to the active sheet in this book view.
# @option [Integer] x_window Specifies the X coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips.
# @option [Integer] y_window Specifies the Y coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips.
# @option [Integer] window_width Specifies the width of the workbook window. The unit of measurement for this value is twips.
Expand All @@ -68,7 +68,9 @@ def initialize(options={})
:show_sheet_tabs, :auto_filter_date_grouping



# Serialize the WorkbookView
# @param [String] str
# @return [String]
def to_xml_string(str = '')
str << '<workbookView '
serialized_attributes str
Expand Down
5 changes: 4 additions & 1 deletion lib/axlsx/workbook/worksheet/cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def initialize(row, value = nil, options = {})
:shadow, :condense, :extend, :u,
:vertAlign, :sz, :color, :scheme].freeze

# An array of valid cell types
CELL_TYPES = [:date, :time, :float, :integer, :richtext,
:string, :boolean, :iso_8601, :text].freeze

Expand All @@ -79,7 +80,7 @@ def style
# @return [Row]
attr_reader :row

# The cell's data type. Currently only six types are supported, :date, :time, :float, :integer, :string and :boolean.
# The cell's data type.
# Changing the type for a cell will recast the value into that type. If no type option is specified in the constructor, the type is
# automatically determed.
# @see Cell#cell_type_from_value
Expand Down Expand Up @@ -348,6 +349,8 @@ def name=(label)
# returns the name of the cell
attr_reader :name

# Attempts to determine the correct width for this cell's content
# @return [Float]
def autowidth
return if is_formula? || value.nil?
if contains_rich_text?
Expand Down
3 changes: 3 additions & 0 deletions lib/axlsx/workbook/worksheet/cfvos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def initialize
super(Cfvo)
end

# Serialize the Cfvo object
# @param [String] str
# @return [String]
def to_xml_string(str='')
each { |cfvo| cfvo.to_xml_string(str) }
end
Expand Down
7 changes: 5 additions & 2 deletions lib/axlsx/workbook/worksheet/cols.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Axlsx

# The cols class manages the col object used to manage column widths.
# The cols class manages the col object used to manage column widths.
# This is where the magic happens with autowidth
class Cols < SimpleTypedList

Expand All @@ -10,11 +10,14 @@ def initialize(worksheet)
@worksheet = worksheet
end

# Serialize the Cols object
# @param [String] str
# @return [String]
def to_xml_string(str = '')
return if empty?
str << '<cols>'
each { |item| item.to_xml_string(str) }
str << '</cols>'
str << '</cols>'
end
end
end
2 changes: 1 addition & 1 deletion lib/axlsx/workbook/worksheet/outline_pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class OutlinePr
:apply_styles

# Creates a new OutlinePr object
# @param [Worksheet] worksheet The worksheet that owns this OutlinePr object
# @param [Hash] options used to create the outline_pr
def initialize(options = {})
parse_options options
end
Expand Down
5 changes: 4 additions & 1 deletion lib/axlsx/workbook/worksheet/protected_ranges.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ def add_range(cells)
last
end

# Serializes the protected ranges
# @param [String] str
# @return [String]
def to_xml_string(str = '')
return if empty?
str << '<protectedRanges>'
each { |range| range.to_xml_string(str) }
str << '</protectedRanges>'
str << '</protectedRanges>'
end
end
end
3 changes: 3 additions & 0 deletions lib/axlsx/workbook/worksheet/tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def relationships
map{ |table| Relationship.new(table, TABLE_R, "../#{table.pn}") }
end

# renders the tables xml
# @param [String] str
# @return [String]
def to_xml_string(str = "")
return if empty?
str << "<tableParts count='#{size}'>"
Expand Down
20 changes: 10 additions & 10 deletions lib/axlsx/workbook/worksheet/worksheet_drawing.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Axlsx

# This is a utility class for serialing the drawing node in a
# worksheet. Drawing objects have their own serialization that exports
# a drawing document. This is only for the single node in the
Expand All @@ -17,7 +17,7 @@ def initialize(worksheet)
attr_reader :worksheet

attr_reader :drawing

# adds a chart to the drawing object
# @param [Class] chart_type The type of chart to add
# @param [Hash] options Options to pass on to the drawing and chart
Expand All @@ -26,17 +26,17 @@ def add_chart(chart_type, options)
@drawing ||= Drawing.new worksheet
drawing.add_chart(chart_type, options)
end

# adds an image to the drawing object
# @param [Hash] options Options to pass on to the drawing and image
# @param [Hash] options Options to pass on to the drawing and image
# @see Worksheet#add_image
def add_image(options)
@drawing ||= Drawing.new worksheet
@drawing ||= Drawing.new(worksheet)
drawing.add_image(options)
end
end

# helper method to tell us if the drawing has something in it or not
# @return [Boolean]
# @return [Boolean]
def has_drawing?
@drawing.is_a? Drawing
end
Expand All @@ -45,13 +45,13 @@ def has_drawing?
# @return [Relationship]
def relationship
return unless has_drawing?
Relationship.new(self, DRAWING_R, "../#{drawing.pn}")
Relationship.new(self, DRAWING_R, "../#{drawing.pn}")
end

# Serialize the drawing for the worksheet
# @param [String] str
def to_xml_string(str = '')
return unless has_drawing?
return unless has_drawing?
str << "<drawing r:id='#{relationship.Id}'/>"
end
end
Expand Down

0 comments on commit 83e2398

Please sign in to comment.