Class: MppReader::FieldReader

Inherits:
Object
  • Object
show all
Defined in:
lib/mpp_reader/field_reader.rb

Overview

Decodes a single field value given its FieldMap::Item, the entity’s fixed-data records and the var data block. Ported from MPXJ FieldMap.FieldItem#read; only the data types needed so far are implemented - unknown types decode to nil rather than raising.

Constant Summary collapse

MINUTES_PER_DAY_KEY =
37_748_765
MINUTES_PER_WEEK_KEY =
37_748_766
DAYS_PER_MONTH_KEY =
37_753_743

Instance Method Summary collapse

Constructor Details

#initialize(props) ⇒ FieldReader

Returns a new instance of FieldReader.



11
12
13
14
15
# File 'lib/mpp_reader/field_reader.rb', line 11

def initialize(props)
  @minutes_per_day = positive_or(props.int(MINUTES_PER_DAY_KEY), 480)
  @minutes_per_week = positive_or(props.int(MINUTES_PER_WEEK_KEY), 2400)
  @days_per_month = positive_or(props.short(DAYS_PER_MONTH_KEY), 20)
end

Instance Method Details

#adjusted_duration(value, units) ⇒ Object

Converts a raw duration value (tenths of a minute) using the project’s configured working time.



36
37
38
39
40
41
# File 'lib/mpp_reader/field_reader.rb', line 36

def adjusted_duration(value, units)
  Decode.adjusted_duration(value, units,
                           minutes_per_day: @minutes_per_day,
                           minutes_per_week: @minutes_per_week,
                           days_per_month: @days_per_month)
end

#read(field_map, field, unique_id, fixed_records, var_data) ⇒ Object

fixed_records is an array of byte strings, one per fixed-data block (block 0 = FixedData, block 1 = Fixed2Data).



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mpp_reader/field_reader.rb', line 19

def read(field_map, field, unique_id, fixed_records, var_data)
  item = field_map[field]
  return nil if item.nil?

  case item.location
  when :fixed_data
    record = fixed_records[item.data_block]
    return nil if record.nil? || item.fixed_offset >= record.bytesize

    read_fixed(field_map, item, record, unique_id, fixed_records, var_data)
  when :var_data
    read_var(field_map, item, unique_id, fixed_records, var_data)
  end
end